Added feature request #35
This commit is contained in:
parent
7b54087a63
commit
2a1c3ea554
@ -197,16 +197,63 @@ function setPersistInvidiousPrefs(val) {
|
|||||||
console.log("persistInvidiousPrefs: ", persistInvidiousPrefs)
|
console.log("persistInvidiousPrefs: ", persistInvidiousPrefs)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
let alwaysusePreferred;
|
||||||
|
const getAlwaysusePreferred = () => alwaysusePreferred;
|
||||||
|
function setAlwaysusePreferred(val) {
|
||||||
|
alwaysusePreferred = val;
|
||||||
|
browser.storage.sync.set({ alwaysusePreferred })
|
||||||
|
console.log("alwaysusePreferred: ", alwaysusePreferred)
|
||||||
|
}
|
||||||
|
|
||||||
let invidiousHostNames = () => redirects.invidious.normal.map(link => new URL(link).host);
|
let invidiousHostNames = () => redirects.invidious.normal.map(link => new URL(link).host);
|
||||||
let pipedHostNames = () => redirects.piped.normal.map(link => new URL(link).host);
|
let pipedHostNames = () => redirects.piped.normal.map(link => new URL(link).host);
|
||||||
|
|
||||||
function isYoutube(url) {
|
function isYoutube(url, initiator) {
|
||||||
if (frontend == 'invidious')
|
if (disableYoutube)
|
||||||
return (targets.some((rx) => rx.test(url.href)) | pipedHostNames().includes(url.host));
|
return null;
|
||||||
if (frontend == 'piped')
|
|
||||||
return (targets.some((rx) => rx.test(url.href)) | invidiousHostNames().includes(url.host));
|
if (
|
||||||
|
initiator &&
|
||||||
|
(
|
||||||
|
redirects.invidious.normal.includes(initiator.origin) ||
|
||||||
|
redirects.piped.normal.includes(initiator.origin) ||
|
||||||
|
targets.includes(initiator.host)
|
||||||
|
)
|
||||||
|
)
|
||||||
|
return null;
|
||||||
|
|
||||||
|
if (url.pathname.match(/iframe_api/) || url.pathname.match(/www-widgetapi/)) return null; // Don't redirect YouTube Player API.
|
||||||
|
|
||||||
|
let pipedInstancesList = [...pipedRedirectsChecks, ...pipedCustomRedirects];
|
||||||
|
let invidiousInstancesList = [...invidiousRedirectsChecks, ...invidiousCustomRedirects];
|
||||||
|
let isTargets = targets.some((rx) => rx.test(url.href));
|
||||||
|
let protocolHost = `${url.protocol}//${url.host}`;
|
||||||
|
|
||||||
|
let isInvidious = redirects.invidious.normal.includes(protocolHost);
|
||||||
|
if (isInvidious)
|
||||||
|
for (const iterator of invidiousInstancesList)
|
||||||
|
if (iterator.indexOf(protocolHost) === 0) isInvidious = false;
|
||||||
|
|
||||||
|
let isPiped = redirects.piped.normal.includes(protocolHost);
|
||||||
|
if (isPiped)
|
||||||
|
for (const iterator of pipedInstancesList)
|
||||||
|
if (iterator.indexOf(protocolHost) === 0) isPiped = false;
|
||||||
|
|
||||||
|
if (frontend == 'invidious') {
|
||||||
|
if (alwaysusePreferred)
|
||||||
|
return isTargets | isPiped | isInvidious;
|
||||||
else
|
else
|
||||||
return targets.some((rx) => rx.test(url.href))
|
return isTargets | isPiped;
|
||||||
|
}
|
||||||
|
if (frontend == 'piped') {
|
||||||
|
if (alwaysusePreferred)
|
||||||
|
return isTargets | isPiped | isInvidious;
|
||||||
|
else
|
||||||
|
return isTargets | isInvidious;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
return isTargets
|
||||||
}
|
}
|
||||||
|
|
||||||
async function init() {
|
async function init() {
|
||||||
@ -229,6 +276,7 @@ async function init() {
|
|||||||
"invidiousCustomRedirects",
|
"invidiousCustomRedirects",
|
||||||
"pipedRedirectsChecks",
|
"pipedRedirectsChecks",
|
||||||
"pipedCustomRedirects",
|
"pipedCustomRedirects",
|
||||||
|
"alwaysusePreferred",
|
||||||
],
|
],
|
||||||
(result) => {
|
(result) => {
|
||||||
if (result.youtubeRedirects) redirects = result.youtubeRedirects;
|
if (result.youtubeRedirects) redirects = result.youtubeRedirects;
|
||||||
@ -253,6 +301,8 @@ async function init() {
|
|||||||
|
|
||||||
persistInvidiousPrefs = result.persistInvidiousPrefs ?? false;
|
persistInvidiousPrefs = result.persistInvidiousPrefs ?? false;
|
||||||
|
|
||||||
|
alwaysusePreferred = result.alwaysusePreferred ?? true;
|
||||||
|
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
|
|
||||||
@ -267,27 +317,17 @@ function invidiousInitCookies(tabId) {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function redirect(url, initiator, type) {
|
function redirect(url, type) {
|
||||||
if (disableYoutube)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
if (
|
|
||||||
initiator &&
|
|
||||||
(
|
|
||||||
redirects.invidious.normal.includes(initiator.origin) ||
|
|
||||||
redirects.piped.normal.includes(initiator.origin) ||
|
|
||||||
targets.includes(initiator.host)
|
|
||||||
)
|
|
||||||
)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
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 == 'invidious') {
|
||||||
|
|
||||||
|
let instancesList = [...invidiousRedirectsChecks, ...invidiousCustomRedirects];
|
||||||
|
if (instancesList.length === 0) return null;
|
||||||
|
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||||
|
|
||||||
if (invidiousOnlyEmbeddedVideo && type !== "sub_frame") return null;
|
if (invidiousOnlyEmbeddedVideo && type !== "sub_frame") return null;
|
||||||
|
|
||||||
if (invidiousAlwaysProxy != "DEFAULT") url.searchParams.append("local", invidiousAlwaysProxy);
|
if (invidiousAlwaysProxy != "DEFAULT") url.searchParams.append("local", invidiousAlwaysProxy);
|
||||||
@ -298,35 +338,21 @@ function redirect(url, initiator, type) {
|
|||||||
if (invidiousSubtitles.trim() != '') url.searchParams.append("subtitles", invidiousSubtitles);
|
if (invidiousSubtitles.trim() != '') url.searchParams.append("subtitles", invidiousSubtitles);
|
||||||
if (invidiousAutoplay != "DEFAULT") url.searchParams.append("autoplay", invidiousAutoplay);
|
if (invidiousAutoplay != "DEFAULT") url.searchParams.append("autoplay", invidiousAutoplay);
|
||||||
|
|
||||||
let instancesList = [...invidiousRedirectsChecks, ...invidiousCustomRedirects];
|
|
||||||
|
|
||||||
if (instancesList.length === 0)
|
|
||||||
return null;
|
|
||||||
|
|
||||||
let randomInstance = commonHelper.getRandomInstance(instancesList)
|
|
||||||
|
|
||||||
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') {
|
||||||
|
|
||||||
if (invidiousOnlyEmbeddedVideo && 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;
|
||||||
|
let randomInstance = commonHelper.getRandomInstance(instancesList);
|
||||||
|
|
||||||
let randomInstance = commonHelper.getRandomInstance(instancesList)
|
if (invidiousOnlyEmbeddedVideo && type !== "sub_frame") return null;
|
||||||
|
|
||||||
if (invidiousTheme != "DEFAULT") url.searchParams.append("theme", invidiousTheme);
|
if (invidiousTheme != "DEFAULT") url.searchParams.append("theme", invidiousTheme);
|
||||||
if (invidiousVolume != "--") url.searchParams.append("volume", invidiousVolume / 100);
|
if (invidiousVolume != "--") url.searchParams.append("volume", invidiousVolume / 100);
|
||||||
if (invidiousAutoplay != "DEFAULT") url.searchParams.append("playerAutoPlay", invidiousAutoplay);
|
if (invidiousAutoplay != "DEFAULT") url.searchParams.append("playerAutoPlay", invidiousAutoplay);
|
||||||
|
|
||||||
if (url.hostname.endsWith("youtube.com") || url.hostname.endsWith("youtube-nocookie.com") || invidiousHostNames().includes(url.hostname))
|
|
||||||
return `${randomInstance}${url.pathname.replace("/shorts/", "/watch?v=")}${url.search}`;
|
return `${randomInstance}${url.pathname.replace("/shorts/", "/watch?v=")}${url.search}`;
|
||||||
|
|
||||||
if (url.hostname.endsWith("youtu.be") && url.pathname.length > 1)
|
|
||||||
return `${randomInstance}/watch?v=${url.pathname.substring(1)}`;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
return 'CANCEL';
|
return 'CANCEL';
|
||||||
}
|
}
|
||||||
@ -387,5 +413,8 @@ export default {
|
|||||||
getPipedCustomRedirects,
|
getPipedCustomRedirects,
|
||||||
setPipedCustomRedirects,
|
setPipedCustomRedirects,
|
||||||
|
|
||||||
|
getAlwaysusePreferred,
|
||||||
|
setAlwaysusePreferred,
|
||||||
|
|
||||||
init,
|
init,
|
||||||
};
|
};
|
||||||
|
@ -47,7 +47,7 @@ browser.webRequest.onBeforeRequest.addListener(
|
|||||||
|
|
||||||
if (exceptionsHelper.isException(url)) newUrl = null;
|
if (exceptionsHelper.isException(url)) newUrl = null;
|
||||||
|
|
||||||
else if (youtubeHelper.isYoutube(url)) newUrl = youtubeHelper.redirect(url, initiator, details.type)
|
else if (youtubeHelper.isYoutube(url, initiator)) newUrl = youtubeHelper.redirect(url, initiator, details.type)
|
||||||
|
|
||||||
else if (twitterHelper.isTwitter(url)) newUrl = twitterHelper.redirect(url, initiator);
|
else if (twitterHelper.isTwitter(url)) newUrl = twitterHelper.redirect(url, initiator);
|
||||||
|
|
||||||
|
@ -131,12 +131,16 @@
|
|||||||
<input id="only-embed" type="checkbox" checked />
|
<input id="only-embed" type="checkbox" checked />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
<div class="some-block option-block">
|
||||||
|
<h4>Always use Preffered Instances</h4>
|
||||||
|
<input id="always-use-preferred" type="checkbox" checked />
|
||||||
|
</div>
|
||||||
|
|
||||||
<div class="some-block option-block">
|
<div class="some-block option-block">
|
||||||
<h4>Volume: <span id="volume-value">50%</span></h4>
|
<h4>Volume: <span id="volume-value">50%</span></h4>
|
||||||
<input id="invidious-volume" name="invidious-volume" type="range" min="0" max="100" step="1" />
|
<input id="invidious-volume" name="invidious-volume" type="range" min="0" max="100" step="1" />
|
||||||
<button type="button" class="default" id="clear-invidious-volume">
|
<button type="button" class="default" id="clear-invidious-volume">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px"
|
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor">
|
||||||
fill="currentColor">
|
|
||||||
<path d="M0 0h24v24H0V0z" fill="none" />
|
<path d="M0 0h24v24H0V0z" fill="none" />
|
||||||
<path
|
<path
|
||||||
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z" />
|
d="M19 6.41L17.59 5 12 10.59 6.41 5 5 6.41 10.59 12 5 17.59 6.41 19 12 13.41 17.59 19 19 17.59 13.41 12 19 6.41z" />
|
||||||
@ -218,8 +222,7 @@
|
|||||||
<div class="some-block option-block">
|
<div class="some-block option-block">
|
||||||
<input id="invidious-custom-instance" placeholder="https://invidious.com" type="url" />
|
<input id="invidious-custom-instance" placeholder="https://invidious.com" type="url" />
|
||||||
<button type="submit" class="add" id="invidious-add-instance">
|
<button type="submit" class="add" id="invidious-add-instance">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px"
|
<svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor">
|
||||||
fill="currentColor">
|
|
||||||
<path d="M0 0h24v24H0V0z" fill="none" />
|
<path d="M0 0h24v24H0V0z" fill="none" />
|
||||||
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
|
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
|
||||||
</svg>
|
</svg>
|
||||||
@ -247,8 +250,7 @@
|
|||||||
<div class="some-block option-block">
|
<div class="some-block option-block">
|
||||||
<input id="piped-custom-instance" placeholder="https://piped.com" type="url" />
|
<input id="piped-custom-instance" placeholder="https://piped.com" type="url" />
|
||||||
<button type="submit" class="add" id="piped-add-instance">
|
<button type="submit" class="add" id="piped-add-instance">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px"
|
<svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor">
|
||||||
fill="currentColor">
|
|
||||||
<path d="M0 0h24v24H0V0z" fill="none" />
|
<path d="M0 0h24v24H0V0z" fill="none" />
|
||||||
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
|
<path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
|
||||||
</svg>
|
</svg>
|
||||||
|
@ -6,6 +6,7 @@ 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")
|
||||||
|
|
||||||
function changeFrontendsSettings(frontend) {
|
function changeFrontendsSettings(frontend) {
|
||||||
if (frontend == 'piped') {
|
if (frontend == 'piped') {
|
||||||
invidiousPipedDivElement.style.display = 'block'
|
invidiousPipedDivElement.style.display = 'block'
|
||||||
@ -57,7 +58,6 @@ invidiousClearVolumeElement.addEventListener("click",
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
let invidiousAutoplayElement = document.getElementById("invidious-autoplay");
|
let invidiousAutoplayElement = document.getElementById("invidious-autoplay");
|
||||||
invidiousAutoplayElement.addEventListener("change",
|
invidiousAutoplayElement.addEventListener("change",
|
||||||
(event) => youtubeHelper.setInvidiousAutoplay(event.target.options[invidiousAutoplayElement.selectedIndex].value)
|
(event) => youtubeHelper.setInvidiousAutoplay(event.target.options[invidiousAutoplayElement.selectedIndex].value)
|
||||||
@ -68,12 +68,18 @@ invidiousOnlyEmbeddedVideoElement.addEventListener("change",
|
|||||||
(event) => youtubeHelper.setInvidiousOnlyEmbeddedVideo(event.target.checked)
|
(event) => youtubeHelper.setInvidiousOnlyEmbeddedVideo(event.target.checked)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
let alwaysUsePreferredElement = document.getElementById("always-use-preferred")
|
||||||
|
alwaysUsePreferredElement.addEventListener("change",
|
||||||
|
(event) => youtubeHelper.setAlwaysusePreferred(event.target.checked)
|
||||||
|
);
|
||||||
|
|
||||||
youtubeHelper.init().then(() => {
|
youtubeHelper.init().then(() => {
|
||||||
disableYoutubeElement.checked = !youtubeHelper.getDisableYoutube();
|
disableYoutubeElement.checked = !youtubeHelper.getDisableYoutube();
|
||||||
invidiousThemeElement.checked = youtubeHelper.getInvidiousTheme();
|
invidiousThemeElement.checked = youtubeHelper.getInvidiousTheme();
|
||||||
invidiousVolumeElement.value = youtubeHelper.getInvidiousVolume();
|
invidiousVolumeElement.value = youtubeHelper.getInvidiousVolume();
|
||||||
invidiousVolumeValueElement.textContent = `${youtubeHelper.getInvidiousVolume()}%`;
|
invidiousVolumeValueElement.textContent = `${youtubeHelper.getInvidiousVolume()}%`;
|
||||||
invidiousOnlyEmbeddedVideoElement.checked = youtubeHelper.getInvidiousOnlyEmbeddedVideo();
|
invidiousOnlyEmbeddedVideoElement.checked = youtubeHelper.getInvidiousOnlyEmbeddedVideo();
|
||||||
|
alwaysUsePreferredElement.checked = youtubeHelper.getAlwaysusePreferred();
|
||||||
invidiousAutoplayElement.checked = youtubeHelper.getInvidiousAutoplay();
|
invidiousAutoplayElement.checked = youtubeHelper.getInvidiousAutoplay();
|
||||||
let frontend = youtubeHelper.getFrontend();
|
let frontend = youtubeHelper.getFrontend();
|
||||||
youtubeFrontendElement.value = frontend;
|
youtubeFrontendElement.value = frontend;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user