Fix YouTube and YT Music typos #293

This commit is contained in:
ManeraKai 2022-05-30 19:39:05 +03:00
parent b822e0eaba
commit 32dfb779c4
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
3 changed files with 28 additions and 50 deletions

View File

@ -58,7 +58,7 @@ function setRedirects(val) {
let
disableYoutube,
OnlyEmbeddedVideo,
onlyEmbeddedVideo,
youtubeFrontend,
youtubeProtocol,
youtubeEmbedFrontend,
@ -81,7 +81,7 @@ function init() {
browser.storage.local.get(
[
"disableYoutube",
"OnlyEmbeddedVideo",
"onlyEmbeddedVideo",
"youtubeFrontend",
"youtubeProtocol",
"youtubeEmbedFrontend",
@ -101,7 +101,7 @@ function init() {
],
r => {
disableYoutube = r.disableYoutube;
OnlyEmbeddedVideo = r.OnlyEmbeddedVideo;
onlyEmbeddedVideo = r.onlyEmbeddedVideo;
youtubeFrontend = r.youtubeFrontend;
youtubeProtocol = r.youtubeProtocol;
youtubeEmbedFrontend = r.youtubeEmbedFrontend;
@ -165,66 +165,46 @@ function redirect(url, details, initiator) {
const isFrontendPiped = youtubeEmbedFrontend == 'piped';
const isFrontendPipedMaterial = youtubeEmbedFrontend == 'pipedMaterial';
const isOnlyEmbeddedVideo = OnlyEmbeddedVideo == 'onlyNotEmbedded';
const isOnlyNotEmbedded = OnlyEmbeddedVideo == 'onlyNotEmbedded'
const isOnlyEmbeddedVideo = onlyEmbeddedVideo == 'onlyEmbedded';
const isOnlyNotEmbedded = onlyEmbeddedVideo == 'onlyNotEmbedded'
const is_main_frame = details.type === "main_frame";
const is_sub_frame = details.type === "sub_frame";
const main_frame = details.type === "main_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 (youtubeFrontend == 'yatte' && is_main_frame)
return url.href.replace(/^https?:\/{2}/, 'yattee://');
if (isOnlyEmbeddedVideo && !sub_frame) return;
if (isOnlyNotEmbedded && sub_frame) return;
else if (isFreetube && is_main_frame)
return `freetube://https:${url.pathname}${url.search}`;
if ((isFreetube || isYatte) && sub_frame && isFrontendYoutube) return;
else if (isFreetube && params && isFrontendYoutube)
return;
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 (isYatte && main_frame) return url.href.replace(/^https?:\/{2}/, 'yattee://');
if (isFreetube && main_frame) return `freetube://https://${url.pathname}${url.search}`;
if (isInvidious || ((isFreetube || isYatte) && sub_frame && isFrontendInvidious)) {
let instancesList;
if (youtubeProtocol == 'normal') instancesList = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects];
else if (youtubeProtocol == 'tor') instancesList = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects];
if (instancesList.length === 0) return;
let randomInstance = utils.getRandomInstance(instancesList);
const randomInstance = utils.getRandomInstance(instancesList);
return `${randomInstance}${url.pathname}${url.search}`;
} else if (isPiped || ((isFreetube || isYatte) && isFrontendPiped && is_sub_frame)) {
if (isOnlyEmbeddedVideo && !is_sub_frame) return;
if (
isOnlyNotEmbedded && params &&
!((isFreetube || isYatte) && isFrontendPiped && is_sub_frame)
) return;
}
if (isPiped || ((isFreetube || isYatte) && sub_frame && isFrontendPiped)) {
let instancesList;
if (youtubeProtocol == 'normal') instancesList = [...pipedNormalRedirectsChecks, ...pipedNormalCustomRedirects];
else if (youtubeProtocol == 'tor') instancesList = [...pipedTorRedirectsChecks, ...pipedTorCustomRedirects];
if (instancesList.length === 0) return;
const randomInstance = utils.getRandomInstance(instancesList);
return `${randomInstance}${url.pathname}${url.search}`;
}
else if (isPipedMaterial || ((isFreetube || isYatte) && isFrontendPipedMaterial && is_sub_frame)) {
if (isOnlyEmbeddedVideo && details.type !== "sub_frame") return;
if (
isOnlyNotEmbedded && params &&
!((isFreetube || isYatte) && isFrontendPipedMaterial && is_sub_frame)
) return;
if (isPipedMaterial || ((isFreetube || isYatte) && sub_frame && isFrontendPipedMaterial)) {
let instancesList;
if (youtubeProtocol == 'normal') instancesList = [...pipedMaterialNormalRedirectsChecks, ...pipedMaterialNormalCustomRedirects];
else if (youtubeProtocol == 'tor') instancesList = [...pipedMaterialTorRedirectsChecks, ...pipedMaterialTorCustomRedirects];
const randomInstance = utils.getRandomInstance(instancesList);
return `${randomInstance}${url.pathname}${url.search}`;
}
else return 'CANCEL';
return 'CANCEL';
}
function reverse(url) {
@ -292,7 +272,7 @@ function initDefaults() {
await browser.storage.local.set({
disableYoutube: false,
enableYoutubeCustomSettings: false,
OnlyEmbeddedVideo: 'both',
onlyEmbeddedVideo: 'both',
youtubeRedirects: redirects,

View File

@ -66,19 +66,17 @@ https://beatbump.ml/release?id=MPREb_QygdC0wEoLe
https://music.youtube.com/watch?v=R6gSMSYKhKU&list=OLAK5uy_n-9HVh3cryV2gREZM9Sc0JwEKYjjfi0dU
*/
function redirect(url, type, initiator) {
function redirect(url) {
if (disableYoutubeMusic) return;
if (!targets.some(rx => rx.test(url.href))) return;
let instancesList = [...beatbumpNormalRedirectsChecks, ...beatbumpNormalCustomRedirects];
if (instancesList.length === 0) return;
const randomInstance = utils.getRandomInstance(instancesList);
resolve(
`${randomInstance}${url.pathname}${url.search}`
.replace("/watch?v=", "/listen?id=")
.replace("/channel/", "/artist/")
.replace("/playlist?list=", "/playlist/VL")
);
return `${randomInstance}${url.pathname}${url.search}`
.replace("/watch?v=", "/listen?id=")
.replace("/channel/", "/artist/")
.replace("/playlist?list=", "/playlist/VL");
}
async function initDefaults() {

View File

@ -8,7 +8,7 @@ let pipedDiv = document.getElementById("piped");
let pipedMaterialDiv = document.getElementById("pipedMaterial");
let freetubeYatteeDiv = document.getElementById("freetube-yatte");
let youtubeEmbedFrontend = document.getElementById("youtube-embed-frontend");
let OnlyEmbeddedVideo = document.getElementById("only-embed");
let onlyEmbeddedVideo = document.getElementById("only-embed");
let protoco = document.getElementById("protocol");
function changeFrontendsSettings() {
@ -101,7 +101,7 @@ document.addEventListener("change", async () => {
disableYoutube: !disableYoutube.checked,
youtubeFrontend: youtubeFrontend.value,
youtubeEmbedFrontend: youtubeEmbedFrontend.value,
OnlyEmbeddedVideo: OnlyEmbeddedVideo.value,
onlyEmbeddedVideo: onlyEmbeddedVideo.value,
youtubeProtocol: protoco.value,
})
changeProtocolSettings();
@ -112,7 +112,7 @@ document.addEventListener("change", async () => {
browser.storage.local.get(
[
"disableYoutube",
"OnlyEmbeddedVideo",
"onlyEmbeddedVideo",
"youtubeRedirects",
"youtubeFrontend",
@ -121,7 +121,7 @@ browser.storage.local.get(
],
r => {
disableYoutube.checked = !r.disableYoutube;
OnlyEmbeddedVideo.value = r.OnlyEmbeddedVideo;
onlyEmbeddedVideo.value = r.onlyEmbeddedVideo;
youtubeFrontend.value = r.youtubeFrontend;
protoco.value = r.youtubeProtocol;