Fix YouTube and YT Music typos #293
This commit is contained in:
parent
b822e0eaba
commit
32dfb779c4
@ -58,7 +58,7 @@ function setRedirects(val) {
|
|||||||
|
|
||||||
let
|
let
|
||||||
disableYoutube,
|
disableYoutube,
|
||||||
OnlyEmbeddedVideo,
|
onlyEmbeddedVideo,
|
||||||
youtubeFrontend,
|
youtubeFrontend,
|
||||||
youtubeProtocol,
|
youtubeProtocol,
|
||||||
youtubeEmbedFrontend,
|
youtubeEmbedFrontend,
|
||||||
@ -81,7 +81,7 @@ function init() {
|
|||||||
browser.storage.local.get(
|
browser.storage.local.get(
|
||||||
[
|
[
|
||||||
"disableYoutube",
|
"disableYoutube",
|
||||||
"OnlyEmbeddedVideo",
|
"onlyEmbeddedVideo",
|
||||||
"youtubeFrontend",
|
"youtubeFrontend",
|
||||||
"youtubeProtocol",
|
"youtubeProtocol",
|
||||||
"youtubeEmbedFrontend",
|
"youtubeEmbedFrontend",
|
||||||
@ -101,7 +101,7 @@ function init() {
|
|||||||
],
|
],
|
||||||
r => {
|
r => {
|
||||||
disableYoutube = r.disableYoutube;
|
disableYoutube = r.disableYoutube;
|
||||||
OnlyEmbeddedVideo = r.OnlyEmbeddedVideo;
|
onlyEmbeddedVideo = r.onlyEmbeddedVideo;
|
||||||
youtubeFrontend = r.youtubeFrontend;
|
youtubeFrontend = r.youtubeFrontend;
|
||||||
youtubeProtocol = r.youtubeProtocol;
|
youtubeProtocol = r.youtubeProtocol;
|
||||||
youtubeEmbedFrontend = r.youtubeEmbedFrontend;
|
youtubeEmbedFrontend = r.youtubeEmbedFrontend;
|
||||||
@ -165,66 +165,46 @@ function redirect(url, details, initiator) {
|
|||||||
const isFrontendPiped = youtubeEmbedFrontend == 'piped';
|
const isFrontendPiped = youtubeEmbedFrontend == 'piped';
|
||||||
const isFrontendPipedMaterial = youtubeEmbedFrontend == 'pipedMaterial';
|
const isFrontendPipedMaterial = youtubeEmbedFrontend == 'pipedMaterial';
|
||||||
|
|
||||||
const isOnlyEmbeddedVideo = OnlyEmbeddedVideo == 'onlyNotEmbedded';
|
const isOnlyEmbeddedVideo = onlyEmbeddedVideo == 'onlyEmbedded';
|
||||||
const isOnlyNotEmbedded = OnlyEmbeddedVideo == 'onlyNotEmbedded'
|
const isOnlyNotEmbedded = onlyEmbeddedVideo == 'onlyNotEmbedded'
|
||||||
|
|
||||||
const is_main_frame = details.type === "main_frame";
|
const main_frame = details.type === "main_frame";
|
||||||
const is_sub_frame = details.type === "sub_frame";
|
const sub_frame = details.type === "sub_frame";
|
||||||
|
|
||||||
if (url.pathname.match(/iframe_api/) || url.pathname.match(/www-widgetapi/)) return; // Don't redirect YouTube Player API.
|
if (url.pathname.match(/iframe_api/) || url.pathname.match(/www-widgetapi/)) return; // Don't redirect YouTube Player API.
|
||||||
|
|
||||||
if (youtubeFrontend == 'yatte' && is_main_frame)
|
if (isOnlyEmbeddedVideo && !sub_frame) return;
|
||||||
return url.href.replace(/^https?:\/{2}/, 'yattee://');
|
if (isOnlyNotEmbedded && sub_frame) return;
|
||||||
|
|
||||||
else if (isFreetube && is_main_frame)
|
if ((isFreetube || isYatte) && sub_frame && isFrontendYoutube) return;
|
||||||
return `freetube://https:${url.pathname}${url.search}`;
|
|
||||||
|
|
||||||
else if (isFreetube && params && isFrontendYoutube)
|
if (isYatte && main_frame) return url.href.replace(/^https?:\/{2}/, 'yattee://');
|
||||||
return;
|
if (isFreetube && main_frame) return `freetube://https://${url.pathname}${url.search}`;
|
||||||
|
|
||||||
else if (isInvidious || ((isFreetube || isYatte) && isFrontendInvidious && is_sub_frame)) {
|
|
||||||
|
|
||||||
if (isOnlyEmbeddedVideo && !is_sub_frame) return;
|
|
||||||
if (isOnlyNotEmbedded && params && !((isFreetube || isYatte) && isFrontendInvidious && is_sub_frame)) return;
|
|
||||||
|
|
||||||
|
if (isInvidious || ((isFreetube || isYatte) && sub_frame && isFrontendInvidious)) {
|
||||||
let instancesList;
|
let instancesList;
|
||||||
if (youtubeProtocol == 'normal') instancesList = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects];
|
if (youtubeProtocol == 'normal') instancesList = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects];
|
||||||
else if (youtubeProtocol == 'tor') instancesList = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects];
|
else if (youtubeProtocol == 'tor') instancesList = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects];
|
||||||
if (instancesList.length === 0) return;
|
if (instancesList.length === 0) return;
|
||||||
let randomInstance = utils.getRandomInstance(instancesList);
|
const randomInstance = utils.getRandomInstance(instancesList);
|
||||||
|
|
||||||
return `${randomInstance}${url.pathname}${url.search}`;
|
return `${randomInstance}${url.pathname}${url.search}`;
|
||||||
} else if (isPiped || ((isFreetube || isYatte) && isFrontendPiped && is_sub_frame)) {
|
}
|
||||||
|
if (isPiped || ((isFreetube || isYatte) && sub_frame && isFrontendPiped)) {
|
||||||
if (isOnlyEmbeddedVideo && !is_sub_frame) return;
|
|
||||||
if (
|
|
||||||
isOnlyNotEmbedded && params &&
|
|
||||||
!((isFreetube || isYatte) && isFrontendPiped && is_sub_frame)
|
|
||||||
) return;
|
|
||||||
|
|
||||||
let instancesList;
|
let instancesList;
|
||||||
if (youtubeProtocol == 'normal') instancesList = [...pipedNormalRedirectsChecks, ...pipedNormalCustomRedirects];
|
if (youtubeProtocol == 'normal') instancesList = [...pipedNormalRedirectsChecks, ...pipedNormalCustomRedirects];
|
||||||
else if (youtubeProtocol == 'tor') instancesList = [...pipedTorRedirectsChecks, ...pipedTorCustomRedirects];
|
else if (youtubeProtocol == 'tor') instancesList = [...pipedTorRedirectsChecks, ...pipedTorCustomRedirects];
|
||||||
if (instancesList.length === 0) return;
|
if (instancesList.length === 0) return;
|
||||||
|
|
||||||
const randomInstance = utils.getRandomInstance(instancesList);
|
const randomInstance = utils.getRandomInstance(instancesList);
|
||||||
return `${randomInstance}${url.pathname}${url.search}`;
|
return `${randomInstance}${url.pathname}${url.search}`;
|
||||||
}
|
}
|
||||||
else if (isPipedMaterial || ((isFreetube || isYatte) && isFrontendPipedMaterial && is_sub_frame)) {
|
if (isPipedMaterial || ((isFreetube || isYatte) && sub_frame && isFrontendPipedMaterial)) {
|
||||||
if (isOnlyEmbeddedVideo && details.type !== "sub_frame") return;
|
|
||||||
if (
|
|
||||||
isOnlyNotEmbedded && params &&
|
|
||||||
!((isFreetube || isYatte) && isFrontendPipedMaterial && is_sub_frame)
|
|
||||||
) return;
|
|
||||||
|
|
||||||
let instancesList;
|
let instancesList;
|
||||||
if (youtubeProtocol == 'normal') instancesList = [...pipedMaterialNormalRedirectsChecks, ...pipedMaterialNormalCustomRedirects];
|
if (youtubeProtocol == 'normal') instancesList = [...pipedMaterialNormalRedirectsChecks, ...pipedMaterialNormalCustomRedirects];
|
||||||
else if (youtubeProtocol == 'tor') instancesList = [...pipedMaterialTorRedirectsChecks, ...pipedMaterialTorCustomRedirects];
|
else if (youtubeProtocol == 'tor') instancesList = [...pipedMaterialTorRedirectsChecks, ...pipedMaterialTorCustomRedirects];
|
||||||
|
|
||||||
const randomInstance = utils.getRandomInstance(instancesList);
|
const randomInstance = utils.getRandomInstance(instancesList);
|
||||||
return `${randomInstance}${url.pathname}${url.search}`;
|
return `${randomInstance}${url.pathname}${url.search}`;
|
||||||
}
|
}
|
||||||
else return 'CANCEL';
|
return 'CANCEL';
|
||||||
}
|
}
|
||||||
|
|
||||||
function reverse(url) {
|
function reverse(url) {
|
||||||
@ -292,7 +272,7 @@ function initDefaults() {
|
|||||||
await browser.storage.local.set({
|
await browser.storage.local.set({
|
||||||
disableYoutube: false,
|
disableYoutube: false,
|
||||||
enableYoutubeCustomSettings: false,
|
enableYoutubeCustomSettings: false,
|
||||||
OnlyEmbeddedVideo: 'both',
|
onlyEmbeddedVideo: 'both',
|
||||||
|
|
||||||
youtubeRedirects: redirects,
|
youtubeRedirects: redirects,
|
||||||
|
|
||||||
|
@ -66,19 +66,17 @@ https://beatbump.ml/release?id=MPREb_QygdC0wEoLe
|
|||||||
|
|
||||||
https://music.youtube.com/watch?v=R6gSMSYKhKU&list=OLAK5uy_n-9HVh3cryV2gREZM9Sc0JwEKYjjfi0dU
|
https://music.youtube.com/watch?v=R6gSMSYKhKU&list=OLAK5uy_n-9HVh3cryV2gREZM9Sc0JwEKYjjfi0dU
|
||||||
*/
|
*/
|
||||||
function redirect(url, type, initiator) {
|
function redirect(url) {
|
||||||
if (disableYoutubeMusic) return;
|
if (disableYoutubeMusic) return;
|
||||||
if (!targets.some(rx => rx.test(url.href))) return;
|
if (!targets.some(rx => rx.test(url.href))) return;
|
||||||
|
|
||||||
let instancesList = [...beatbumpNormalRedirectsChecks, ...beatbumpNormalCustomRedirects];
|
let instancesList = [...beatbumpNormalRedirectsChecks, ...beatbumpNormalCustomRedirects];
|
||||||
if (instancesList.length === 0) return;
|
if (instancesList.length === 0) return;
|
||||||
const randomInstance = utils.getRandomInstance(instancesList);
|
const randomInstance = utils.getRandomInstance(instancesList);
|
||||||
resolve(
|
return `${randomInstance}${url.pathname}${url.search}`
|
||||||
`${randomInstance}${url.pathname}${url.search}`
|
.replace("/watch?v=", "/listen?id=")
|
||||||
.replace("/watch?v=", "/listen?id=")
|
.replace("/channel/", "/artist/")
|
||||||
.replace("/channel/", "/artist/")
|
.replace("/playlist?list=", "/playlist/VL");
|
||||||
.replace("/playlist?list=", "/playlist/VL")
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
async function initDefaults() {
|
async function initDefaults() {
|
||||||
|
@ -8,7 +8,7 @@ let pipedDiv = document.getElementById("piped");
|
|||||||
let pipedMaterialDiv = document.getElementById("pipedMaterial");
|
let pipedMaterialDiv = document.getElementById("pipedMaterial");
|
||||||
let freetubeYatteeDiv = document.getElementById("freetube-yatte");
|
let freetubeYatteeDiv = document.getElementById("freetube-yatte");
|
||||||
let youtubeEmbedFrontend = document.getElementById("youtube-embed-frontend");
|
let youtubeEmbedFrontend = document.getElementById("youtube-embed-frontend");
|
||||||
let OnlyEmbeddedVideo = document.getElementById("only-embed");
|
let onlyEmbeddedVideo = document.getElementById("only-embed");
|
||||||
let protoco = document.getElementById("protocol");
|
let protoco = document.getElementById("protocol");
|
||||||
|
|
||||||
function changeFrontendsSettings() {
|
function changeFrontendsSettings() {
|
||||||
@ -101,7 +101,7 @@ document.addEventListener("change", async () => {
|
|||||||
disableYoutube: !disableYoutube.checked,
|
disableYoutube: !disableYoutube.checked,
|
||||||
youtubeFrontend: youtubeFrontend.value,
|
youtubeFrontend: youtubeFrontend.value,
|
||||||
youtubeEmbedFrontend: youtubeEmbedFrontend.value,
|
youtubeEmbedFrontend: youtubeEmbedFrontend.value,
|
||||||
OnlyEmbeddedVideo: OnlyEmbeddedVideo.value,
|
onlyEmbeddedVideo: onlyEmbeddedVideo.value,
|
||||||
youtubeProtocol: protoco.value,
|
youtubeProtocol: protoco.value,
|
||||||
})
|
})
|
||||||
changeProtocolSettings();
|
changeProtocolSettings();
|
||||||
@ -112,7 +112,7 @@ document.addEventListener("change", async () => {
|
|||||||
browser.storage.local.get(
|
browser.storage.local.get(
|
||||||
[
|
[
|
||||||
"disableYoutube",
|
"disableYoutube",
|
||||||
"OnlyEmbeddedVideo",
|
"onlyEmbeddedVideo",
|
||||||
"youtubeRedirects",
|
"youtubeRedirects",
|
||||||
"youtubeFrontend",
|
"youtubeFrontend",
|
||||||
|
|
||||||
@ -121,7 +121,7 @@ browser.storage.local.get(
|
|||||||
],
|
],
|
||||||
r => {
|
r => {
|
||||||
disableYoutube.checked = !r.disableYoutube;
|
disableYoutube.checked = !r.disableYoutube;
|
||||||
OnlyEmbeddedVideo.value = r.OnlyEmbeddedVideo;
|
onlyEmbeddedVideo.value = r.onlyEmbeddedVideo;
|
||||||
youtubeFrontend.value = r.youtubeFrontend;
|
youtubeFrontend.value = r.youtubeFrontend;
|
||||||
protoco.value = r.youtubeProtocol;
|
protoco.value = r.youtubeProtocol;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user