From 0e889c2d4285b3cf1767cb9b8a3957ec5392324d Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Sun, 3 Apr 2022 13:55:54 +0300 Subject: Restructured exceptions to behave in another way #164 #161 --- src/pages/background/background.js | 16 +++--- src/pages/options/youtube/embed-exceptions.js | 79 --------------------------- src/pages/options/youtube/youtube.html | 26 --------- 3 files changed, 9 insertions(+), 112 deletions(-) delete mode 100644 src/pages/options/youtube/embed-exceptions.js (limited to 'src/pages') diff --git a/src/pages/background/background.js b/src/pages/background/background.js index e54627c4..650a48a8 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -92,7 +92,12 @@ browser.webRequest.onBeforeRequest.addListener( if (!newUrl) newUrl = wikipediaHelper.redirect(url); - if (generalHelper.isException(url, initiator)) newUrl = null; + if ( + details.frameAncestors && details.frameAncestors.length > 0 && + generalHelper.isException(new URL(details.frameAncestors[0].url)) + ) newUrl = null; + + if (generalHelper.isException(url)) newUrl = null; if (BYPASSTABs.includes(details.tabId)) newUrl = null; @@ -103,15 +108,11 @@ browser.webRequest.onBeforeRequest.addListener( } else if (newUrl == 'BYPASSTAB') { console.log(`Bybassed ${details.tabId} ${url}`); - BYPASSTABs.push(details.tabId); + if (!BYPASSTABs.includes(details.tabId)) BYPASSTABs.push(details.tabId); return null; } else { console.info("Redirecting", url.href, "=>", newUrl); - // let wewe = new URL(newUrl); - // console.log("wewe", wewe.search); - // console.log("path", wewe.pathname); - // console.log("searchParams", wewe.searchParams); return { redirectUrl: newUrl }; } } @@ -206,7 +207,8 @@ browser.tabs.onUpdated.addListener( if (instagramHelper.isBibliogram(url)) instagramHelper.initBibliogramCookies(url); // if (changeInfo.url && youtubeHelper.isPipedorInvidious(url, 'main_frame', 'pipedMaterial')) youtubeHelper.initPipedMaterialLocalStorage(tabId); - }); + } +); function changeWholeInstance(url) { let newUrl = youtubeHelper.switchInstance(url); diff --git a/src/pages/options/youtube/embed-exceptions.js b/src/pages/options/youtube/embed-exceptions.js deleted file mode 100644 index 06be99c4..00000000 --- a/src/pages/options/youtube/embed-exceptions.js +++ /dev/null @@ -1,79 +0,0 @@ -"use strict"; -window.browser = window.browser || window.chrome; - -import youtubeHelper from "../../../assets/javascripts/helpers/youtube/youtube.js"; - -let nameCustomInstanceInput = document.getElementById("exceptions-custom-instance"); -let instanceTypeElement = document.getElementById("exceptions-custom-instance-type"); -let instanceType = "url" - -youtubeHelper.init().then(() => { - instanceTypeElement.addEventListener("change", - (event) => { - instanceType = event.target.options[instanceTypeElement.selectedIndex].value - if (instanceType == 'url') { - nameCustomInstanceInput.setAttribute("type", "url"); - nameCustomInstanceInput.setAttribute("placeholder", "https://www.google.com"); - } - else if (instanceType == 'regex') { - nameCustomInstanceInput.setAttribute("type", "text"); - nameCustomInstanceInput.setAttribute("placeholder", "https?:\/\/(www\.|music|)youtube\.com\/watch\?v\=..*"); - } - } - ) - let exceptionsCustomInstances = youtubeHelper.getExceptions(); - function calcExceptionsCustomInstances() { - document.getElementById("exceptions-custom-checklist").innerHTML = - [...exceptionsCustomInstances.url, ...exceptionsCustomInstances.regex].map( - (x) => `
${x} -
-
` - ).join('\n'); - - for (const x of [...exceptionsCustomInstances.url, ...exceptionsCustomInstances.regex]) { - document.getElementById(`clear-${x}`).addEventListener("click", - () => { - console.log(x); - let index; - index = exceptionsCustomInstances.url.indexOf(x); - if (index > -1) - exceptionsCustomInstances.url.splice(index, 1); - else { - index = exceptionsCustomInstances.regex.indexOf(x); - if (index > -1) - exceptionsCustomInstances.regex.splice(index, 1); - } - youtubeHelper.setExceptions(exceptionsCustomInstances); - calcExceptionsCustomInstances(); - }); - } - } - calcExceptionsCustomInstances(); - document.getElementById("custom-exceptions-instance-form").addEventListener("submit", (event) => { - event.preventDefault(); - - let val - if (instanceType == 'url') { - if (nameCustomInstanceInput.validity.valid) { - let url = new URL(nameCustomInstanceInput.value); - val = `${url.protocol}//${url.host}` - if (!exceptionsCustomInstances.url.includes(val)) exceptionsCustomInstances.url.push(val) - } - } else if (instanceType == 'regex') { - val = nameCustomInstanceInput.value - if (val.trim() != '' && !exceptionsCustomInstances.regex.includes(val)) exceptionsCustomInstances.regex.push(val) - } - if (val) { - youtubeHelper.setExceptions(exceptionsCustomInstances); - console.log("exceptionsCustomInstances", exceptionsCustomInstances) - nameCustomInstanceInput.value = ''; - } - calcExceptionsCustomInstances(); - }) -}) \ No newline at end of file diff --git a/src/pages/options/youtube/youtube.html b/src/pages/options/youtube/youtube.html index fba8de63..c118694d 100644 --- a/src/pages/options/youtube/youtube.html +++ b/src/pages/options/youtube/youtube.html @@ -1287,31 +1287,6 @@
- -
-

Embed Exceptions

-
-
-
-
- -   - -   -
- -
-
-
- @@ -1321,7 +1296,6 @@ - -- cgit 1.4.1