about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorManeraKai <manerakai@protonmail.com>2022-04-03 13:55:54 +0300
committerManeraKai <manerakai@protonmail.com>2022-04-03 13:55:54 +0300
commit0e889c2d4285b3cf1767cb9b8a3957ec5392324d (patch)
treeaee145d37c3edbe969a5d7ef5c9fae1de535e7a6
parentFixed some branch merging issues. Bump version => 1.6.2 (diff)
downloadlibredirect-0e889c2d4285b3cf1767cb9b8a3957ec5392324d.zip
Restructured exceptions to behave in another way #164 #161
-rw-r--r--package.json2
-rw-r--r--src/assets/javascripts/helpers/youtube/youtube.js37
-rw-r--r--src/pages/background/background.js16
-rw-r--r--src/pages/options/youtube/embed-exceptions.js79
-rw-r--r--src/pages/options/youtube/youtube.html26
5 files changed, 10 insertions, 150 deletions
diff --git a/package.json b/package.json
index d4a6d2f6..2f8f9abf 100644
--- a/package.json
+++ b/package.json
@@ -6,7 +6,7 @@
     "npm": ">=8.1.2"
   },
   "scripts": {
-    "start": "web-ext run --browser-console --source-dir ./src/ --firefox=/home/esmail/Downloads/ar/firefox/firefox",
+    "start": "web-ext run --browser-console --source-dir ./src/",
     "build": "web-ext build --overwrite-dest --source-dir ./src/",
     "test": "web-ext lint --source-dir ./src/ || true"
   },
diff --git a/src/assets/javascripts/helpers/youtube/youtube.js b/src/assets/javascripts/helpers/youtube/youtube.js
index 9e88eb31..a4b6d38e 100644
--- a/src/assets/javascripts/helpers/youtube/youtube.js
+++ b/src/assets/javascripts/helpers/youtube/youtube.js
@@ -295,28 +295,6 @@ function setBypassWatchOnYoutube(val) {
   console.log("bypassWatchOnYoutube: ", bypassWatchOnYoutube)
 }
 
-let exceptions = {
-  "url": [],
-  "regex": [],
-};
-const getExceptions = () => exceptions;
-function setExceptions(val) {
-  exceptions = val;
-  browser.storage.local.set({ youtubeEmbedExceptions: val })
-  console.log("youtubeEmbedExceptions: ", val)
-}
-
-function isException(url) {
-  for (const item of exceptions.url) {
-    let protocolHost = commonHelper.protocolHost(url);
-    console.log(item, protocolHost)
-    if (item == protocolHost) return true;
-  }
-  for (const item of exceptions.regex)
-    if (new RegExp(item).test(url.href)) return true;
-  return false;
-}
-
 let alwaysUsePreferred;
 function redirect(url, details, initiator) {
   if (disable) return null;
@@ -360,14 +338,6 @@ function redirect(url, details, initiator) {
   if (!targets.some(rx => rx.test(url.href))) return null;
 
   if (
-    details.type != "main_frame" &&
-    details.frameAncestors && details.frameAncestors.length > 0 &&
-    isException(new URL(details.frameAncestors[0].url))
-  ) {
-    console.log(`Canceled ${url.href}`, details.frameAncestors[0].url)
-    return null;
-  }
-  if (
     bypassWatchOnYoutube &&
     initiator && (
       [...redirects.invidious.normal,
@@ -664,7 +634,6 @@ async function init() {
 
             "youtubeProtocol",
 
-            "youtubeEmbedExceptions",
             "bypassWatchOnYoutube"
           ],
           r => { // r = result
@@ -703,8 +672,6 @@ async function init() {
 
             bypassWatchOnYoutube = r.bypassWatchOnYoutube ?? true;
 
-            if (r.youtubeEmbedExceptions) exceptions = r.youtubeEmbedExceptions;
-
             initInvidiousCookies();
 
             resolve();
@@ -882,9 +849,5 @@ export default {
 
   setPipedMaterialRedirects,
 
-  getExceptions,
-  setExceptions,
-  isException,
-
   init,
 };
\ No newline at end of file
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) => `<div>${x}<button class="add" id="clear-${x}">
-                      <svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px"
-                      fill="currentColor">
-                        <path d="M0 0h24v24H0V0z" fill="none" />
-                        <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" />
-                      </svg>
-                    </button>
-                </div>
-                <hr>`
-            ).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 @@
         <div class="checklist" id="pipedMaterial-tor-custom-checklist"></div>
       </div>
     </div>
-
-    <div class="some-block option-block">
-      <h4 data-localise="__MSG_embedExceptions__">Embed Exceptions</h4>
-    </div>
-    <form id="custom-exceptions-instance-form">
-      <div class="some-block option-block">
-        <div class="some-block" style="padding:0;">
-          <input id="exceptions-custom-instance" placeholder="https://www.google.com" type="url" />
-          &nbsp;
-          <select id="exceptions-custom-instance-type">
-            <option value="url">URL</option>
-            <option value="regex">Regex</option>
-          </select>
-          &nbsp;
-        </div>
-        <button type="submit" class="add" id="exceptions-add-instance">
-          <svg xmlns="http://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor">
-            <path d="M0 0h24v24H0V0z" fill="none" />
-            <path d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z" />
-          </svg>
-        </button>
-      </div>
-    </form>
-    <div class="checklist" id="exceptions-custom-checklist"></div>
-    </a>
   </section>
 
   </section>
@@ -1321,7 +1296,6 @@
   <script type="module" src="./invidious.js"></script>
   <script type="module" src="./piped.js"></script>
   <script type="module" src="./pipedMaterial.js"></script>
-  <script type="module" src="./embed-exceptions.js"></script>
   <script type="module" src="../../../assets/javascripts/localise.js"></script>
 </body>