Added embeddedFrontend option to freetube #40
This commit is contained in:
parent
ea092ab7f9
commit
e9cfde7880
|
@ -189,6 +189,14 @@ function setFrontend(val) {
|
||||||
console.log("youtubeFrontend: ", val)
|
console.log("youtubeFrontend: ", val)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let freetubeFrontend;
|
||||||
|
const getFreetubeFrontend = () => freetubeFrontend;
|
||||||
|
function setFreetubeFrontend(val) {
|
||||||
|
freetubeFrontend = val;
|
||||||
|
browser.storage.sync.set({ freetubeFrontend })
|
||||||
|
console.log("freetubeFrontend: ", freetubeFrontend)
|
||||||
|
}
|
||||||
|
|
||||||
let persistInvidiousPrefs;
|
let persistInvidiousPrefs;
|
||||||
const getPersistInvidiousPrefs = () => persistInvidiousPrefs;
|
const getPersistInvidiousPrefs = () => persistInvidiousPrefs;
|
||||||
function setPersistInvidiousPrefs(val) {
|
function setPersistInvidiousPrefs(val) {
|
||||||
|
@ -209,8 +217,7 @@ function isYoutube(url, initiator) {
|
||||||
if (disable) return false;
|
if (disable) return false;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
initiator &&
|
initiator && (
|
||||||
(
|
|
||||||
[...redirects.invidious.normal, ...invidiousCustomRedirects].includes(initiator.origin) ||
|
[...redirects.invidious.normal, ...invidiousCustomRedirects].includes(initiator.origin) ||
|
||||||
[...redirects.piped.normal, ...pipedCustomRedirects].includes(initiator.origin) ||
|
[...redirects.piped.normal, ...pipedCustomRedirects].includes(initiator.origin) ||
|
||||||
targets.includes(initiator.host)
|
targets.includes(initiator.host)
|
||||||
|
@ -247,12 +254,19 @@ function isYoutube(url, initiator) {
|
||||||
function redirect(url, type) {
|
function redirect(url, type) {
|
||||||
if (url.pathname.match(/iframe_api/) || url.pathname.match(/www-widgetapi/)) return null; // Don't redirect YouTube Player API.
|
if (url.pathname.match(/iframe_api/) || url.pathname.match(/www-widgetapi/)) return null; // Don't redirect YouTube Player API.
|
||||||
|
|
||||||
if (frontend == 'freeTube' && type === "main_frame") {
|
if (frontend == 'freetube' && type === "main_frame")
|
||||||
return `freetube://${url}`;
|
return `freetube://${url}`;
|
||||||
} else if (frontend == 'invidious') {
|
|
||||||
|
else if (frontend == 'freetube' && type !== "main_frame" && freetubeFrontend == "youtube")
|
||||||
|
return null;
|
||||||
|
|
||||||
|
else if (frontend == 'invidious' || (frontend == 'freetube' && freetubeFrontend == 'invidious' && type == "sub_frame")) {
|
||||||
|
|
||||||
if (OnlyEmbeddedVideo == 'onlyEmbedded' && type !== "sub_frame") return null;
|
if (OnlyEmbeddedVideo == 'onlyEmbedded' && type !== "sub_frame") return null;
|
||||||
if (OnlyEmbeddedVideo == 'onlyNotEmbedded' && type !== "main_frame") return null;
|
if (
|
||||||
|
OnlyEmbeddedVideo == 'onlyNotEmbedded' && type !== "main_frame" &&
|
||||||
|
!(frontend == 'freetube' && freetubeFrontend == 'invidious' && type === "sub_frame")
|
||||||
|
) return null;
|
||||||
|
|
||||||
let instancesList = [...invidiousRedirectsChecks, ...invidiousCustomRedirects];
|
let instancesList = [...invidiousRedirectsChecks, ...invidiousCustomRedirects];
|
||||||
if (instancesList.length === 0) return null;
|
if (instancesList.length === 0) return null;
|
||||||
|
@ -269,10 +283,13 @@ function redirect(url, type) {
|
||||||
|
|
||||||
return `${randomInstance}${url.pathname.replace("/shorts/", "/watch?v=")}${url.search}`;
|
return `${randomInstance}${url.pathname.replace("/shorts/", "/watch?v=")}${url.search}`;
|
||||||
|
|
||||||
} else if (frontend == 'piped') {
|
} else if (frontend == 'piped' || (frontend == 'freetube' && freetubeFrontend == 'piped' && type === "sub_frame")) {
|
||||||
|
|
||||||
if (OnlyEmbeddedVideo == 'onlyEmbedded' && type !== "sub_frame") return null;
|
if (OnlyEmbeddedVideo == 'onlyEmbedded' && type !== "sub_frame") return null;
|
||||||
if (OnlyEmbeddedVideo == 'onlyNotEmbedded' && type !== "main_frame") return null;
|
if (
|
||||||
|
OnlyEmbeddedVideo == 'onlyNotEmbedded' && type !== "main_frame" &&
|
||||||
|
!(frontend == 'freetube' && freetubeFrontend == 'piped' && type == "sub_frame")
|
||||||
|
) return null;
|
||||||
|
|
||||||
let instancesList = [...pipedRedirectsChecks, ...pipedCustomRedirects];
|
let instancesList = [...pipedRedirectsChecks, ...pipedCustomRedirects];
|
||||||
if (instancesList.length === 0) return null;
|
if (instancesList.length === 0) return null;
|
||||||
|
@ -284,6 +301,8 @@ function redirect(url, type) {
|
||||||
|
|
||||||
return `${randomInstance}${url.pathname.replace("/shorts/", "/watch?v=")}${url.search}`;
|
return `${randomInstance}${url.pathname.replace("/shorts/", "/watch?v=")}${url.search}`;
|
||||||
}
|
}
|
||||||
|
console.log(freetubeFrontend)
|
||||||
|
console.log(type)
|
||||||
return 'CANCEL';
|
return 'CANCEL';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -318,12 +337,14 @@ async function init() {
|
||||||
"pipedRedirectsChecks",
|
"pipedRedirectsChecks",
|
||||||
"pipedCustomRedirects",
|
"pipedCustomRedirects",
|
||||||
"alwaysusePreferred",
|
"alwaysusePreferred",
|
||||||
|
"freetubeFrontend",
|
||||||
],
|
],
|
||||||
(result) => {
|
(result) => {
|
||||||
if (result.youtubeRedirects) redirects = result.youtubeRedirects;
|
if (result.youtubeRedirects) redirects = result.youtubeRedirects;
|
||||||
|
|
||||||
disable = result.disableYoutube ?? false;
|
disable = result.disableYoutube ?? false;
|
||||||
frontend = result.youtubeFrontend ?? 'piped';
|
frontend = result.youtubeFrontend ?? 'piped';
|
||||||
|
freetubeFrontend = result.freetubeFrontend ?? 'invidious';
|
||||||
|
|
||||||
theme = result.youtubeTheme ?? 'DEFAULT';
|
theme = result.youtubeTheme ?? 'DEFAULT';
|
||||||
volume = result.youtubeVolume ?? '--';
|
volume = result.youtubeVolume ?? '--';
|
||||||
|
@ -357,6 +378,9 @@ export default {
|
||||||
getFrontend,
|
getFrontend,
|
||||||
setFrontend,
|
setFrontend,
|
||||||
|
|
||||||
|
getFreetubeFrontend,
|
||||||
|
setFreetubeFrontend,
|
||||||
|
|
||||||
getRedirects,
|
getRedirects,
|
||||||
getCustomRedirects,
|
getCustomRedirects,
|
||||||
setInvidiousRedirects,
|
setInvidiousRedirects,
|
||||||
|
|
|
@ -92,7 +92,7 @@ browser.webRequest.onResponseStarted.addListener(
|
||||||
var mightyList = getMightyList();
|
var mightyList = getMightyList();
|
||||||
|
|
||||||
if (mightyList.includes(protocolHost)); {
|
if (mightyList.includes(protocolHost)); {
|
||||||
if (responseDetails.statusCode >= 500) {
|
if (responseDetails.statusCode >= 500 && responseDetails.type === "main_frame") {
|
||||||
console.log("Instance is corrupted, redirecting", responseDetails.url);
|
console.log("Instance is corrupted, redirecting", responseDetails.url);
|
||||||
changeInstance(responseDetails.url);
|
changeInstance(responseDetails.url);
|
||||||
}
|
}
|
||||||
|
|
|
@ -119,12 +119,24 @@
|
||||||
<select id="youtube-frontend">
|
<select id="youtube-frontend">
|
||||||
<option value="piped">Piped</option>
|
<option value="piped">Piped</option>
|
||||||
<option value="invidious">Invidious</option>
|
<option value="invidious">Invidious</option>
|
||||||
<option value="freeTube">FreeTube</option>
|
<option value="freetube">FreeTube</option>
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
<div id="freetube">
|
||||||
|
<div class="some-block option-block">
|
||||||
|
<h4>Embedded Videos Frontend</h4>
|
||||||
|
<select id="freetube-embedded-frontend">
|
||||||
|
<option value="invidious">Invidious</option>
|
||||||
|
<option value="piped">Piped</option>
|
||||||
|
<option value="youtube">Youtube</option>
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
<hr>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div id="invidious-piped">
|
<div id="invidious-piped">
|
||||||
<div class="some-block option-block">
|
<div class="some-block option-block">
|
||||||
<h4>Redirect Type</h4>
|
<h4>Redirect Type</h4>
|
||||||
|
@ -237,7 +249,6 @@
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
|
||||||
<div id="piped">
|
<div id="piped">
|
||||||
<hr>
|
<hr>
|
||||||
|
|
||||||
|
|
|
@ -3,22 +3,45 @@ import youtubeHelper from "../../../assets/javascripts/helpers/youtube/youtube.j
|
||||||
let disableYoutubeElement = document.getElementById("disable-invidious");
|
let disableYoutubeElement = document.getElementById("disable-invidious");
|
||||||
|
|
||||||
let youtubeFrontendElement = document.getElementById("youtube-frontend");
|
let youtubeFrontendElement = document.getElementById("youtube-frontend");
|
||||||
let invidiousDivElement = document.getElementById("invidious")
|
let invidiousDivElement = document.getElementById("invidious");
|
||||||
let pipedDivElement = document.getElementById("piped")
|
let pipedDivElement = document.getElementById("piped");
|
||||||
let invidiousPipedDivElement = document.getElementById("invidious-piped")
|
let invidiousPipedDivElement = document.getElementById("invidious-piped");
|
||||||
|
let freetubeDivElement = document.getElementById("freetube");
|
||||||
|
let freetubeFrontendElement = document.getElementById("freetube-embedded-frontend");
|
||||||
|
|
||||||
function changeFrontendsSettings(frontend) {
|
function changeFrontendsSettings(frontend) {
|
||||||
if (frontend == 'piped') {
|
if (frontend == 'piped') {
|
||||||
invidiousPipedDivElement.style.display = 'block'
|
invidiousPipedDivElement.style.display = 'block'
|
||||||
pipedDivElement.style.display = 'block';
|
pipedDivElement.style.display = 'block';
|
||||||
invidiousDivElement.style.display = 'none';
|
invidiousDivElement.style.display = 'none';
|
||||||
|
freetubeDivElement.style.display = 'none';
|
||||||
}
|
}
|
||||||
else if (frontend == 'invidious') {
|
else if (frontend == 'invidious') {
|
||||||
invidiousPipedDivElement.style.display = 'block'
|
invidiousPipedDivElement.style.display = 'block'
|
||||||
pipedDivElement.style.display = 'none';
|
pipedDivElement.style.display = 'none';
|
||||||
invidiousDivElement.style.display = 'block';
|
invidiousDivElement.style.display = 'block';
|
||||||
|
freetubeDivElement.style.display = 'none';
|
||||||
}
|
}
|
||||||
else if (frontend == 'freeTube') {
|
else if (frontend == 'freetube') {
|
||||||
|
invidiousPipedDivElement.style.display = 'none'
|
||||||
|
pipedDivElement.style.display = 'none';
|
||||||
|
invidiousDivElement.style.display = 'none';
|
||||||
|
freetubeDivElement.style.display = 'block';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function changeFreetubeFrontendsSettings(freetubeFrontend) {
|
||||||
|
if (freetubeFrontend == 'invidious') {
|
||||||
|
invidiousPipedDivElement.style.display = 'block'
|
||||||
|
pipedDivElement.style.display = 'none';
|
||||||
|
invidiousDivElement.style.display = 'block';
|
||||||
|
}
|
||||||
|
if (freetubeFrontend == 'piped') {
|
||||||
|
invidiousPipedDivElement.style.display = 'block'
|
||||||
|
pipedDivElement.style.display = 'block';
|
||||||
|
invidiousDivElement.style.display = 'none';
|
||||||
|
}
|
||||||
|
else if (freetubeFrontend == 'youtube') {
|
||||||
invidiousPipedDivElement.style.display = 'none'
|
invidiousPipedDivElement.style.display = 'none'
|
||||||
pipedDivElement.style.display = 'none';
|
pipedDivElement.style.display = 'none';
|
||||||
invidiousDivElement.style.display = 'none';
|
invidiousDivElement.style.display = 'none';
|
||||||
|
@ -31,6 +54,13 @@ youtubeFrontendElement.addEventListener("change",
|
||||||
changeFrontendsSettings(frontend);
|
changeFrontendsSettings(frontend);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
freetubeFrontendElement.addEventListener("change",
|
||||||
|
(event) => {
|
||||||
|
let freetubeFrontend = event.target.options[freetubeFrontendElement.selectedIndex].value
|
||||||
|
youtubeHelper.setFreetubeFrontend(freetubeFrontend);
|
||||||
|
changeFreetubeFrontendsSettings(freetubeFrontend);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
disableYoutubeElement.addEventListener("change",
|
disableYoutubeElement.addEventListener("change",
|
||||||
(event) => youtubeHelper.setDisable(!event.target.checked)
|
(event) => youtubeHelper.setDisable(!event.target.checked)
|
||||||
|
@ -84,4 +114,8 @@ youtubeHelper.init().then(() => {
|
||||||
let frontend = youtubeHelper.getFrontend();
|
let frontend = youtubeHelper.getFrontend();
|
||||||
youtubeFrontendElement.value = frontend;
|
youtubeFrontendElement.value = frontend;
|
||||||
changeFrontendsSettings(frontend);
|
changeFrontendsSettings(frontend);
|
||||||
|
|
||||||
|
let freetubeFrontend = youtubeHelper.getFreetubeFrontend()
|
||||||
|
freetubeFrontendElement.value = freetubeFrontend
|
||||||
|
changeFreetubeFrontendsSettings(freetubeFrontend);
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in New Issue