about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/pages/background/background.js71
-rw-r--r--src/pages/options/options.html2
-rw-r--r--src/pages/options/options.js13
3 files changed, 46 insertions, 40 deletions
diff --git a/src/pages/background/background.js b/src/pages/background/background.js
index 453788c8..d7e37591 100644
--- a/src/pages/background/background.js
+++ b/src/pages/background/background.js
@@ -72,6 +72,7 @@ let useFreeTube;
 let nitterRandomPool;
 let invidiousRandomPool;
 let bibliogramRandomPool;
+let scribeRandomPool;
 let exceptions;
 
 window.browser = window.browser || window.chrome;
@@ -108,6 +109,7 @@ browser.storage.sync.get(
     "nitterRandomPool",
     "invidiousRandomPool",
     "bibliogramRandomPool",
+    "scribeRandomPool",
     "exceptions",
   ],
   (result) => {
@@ -152,6 +154,9 @@ browser.storage.sync.get(
     bibliogramRandomPool = result.bibliogramRandomPool
       ? result.bibliogramRandomPool.split(",")
       : commonHelper.filterInstances(bibliogramInstances);
+    scribeRandomPool = result.scribeRandomPool
+      ? result.scribeRandomPool.split(",")
+      : commonHelper.filterInstances(bibliogramInstances);
   }
 );
 
@@ -244,6 +249,9 @@ browser.storage.onChanged.addListener((changes) => {
   if ("bibliogramRandomPool" in changes) {
     bibliogramRandomPool = changes.bibliogramRandomPool.newValue.split(",");
   }
+  if ("scribeRandomPool" in changes) {
+    scribeRandomPool = changes.scribeRandomPool.newValue.split(",");
+  }
   if ("exceptions" in changes) {
     exceptions = changes.exceptions.newValue.map((e) => {
       return new RegExp(e);
@@ -527,51 +535,38 @@ function redirectReddit(url, initiator, type) {
   return `${redditInstance}${url.pathname}${url.search}`;
 }
 
-function redirectScribe(url, initiator, type) {
+function redirectMedium(url, initiator) {
   if (disableScribe || isException(url, initiator)) {
     return null;
   }
-  // Do not redirect when already on the selected view
-  if (
-    (initiator && initiator.origin === scribeInstance) ||
-    url.origin === scribeInstance
-  ) {
+  if (url.pathname.split("/").includes("home")) {
     return null;
   }
-  // Do not redirect exclusions nor anything other than main_frame
-  if (type !== "main_frame") {
+  if (
+    isFirefox() &&
+    initiator &&
+    (initiator.origin === scribeInstance ||
+      scribeInstances.includes(initiator.origin) ||
+      mediumDomains.includes(initiator.host))
+  ) {
+    browser.storage.sync.set({
+      redirectBypassFlag: true,
+    });
     return null;
   }
-  if (url.host === "i.redd.it") {
-    if (scribeInstance.includes("libredd")) {
-      return `${scribeInstance}/img${url.pathname}${url.search}`;
-    } else if (scribeInstance.includes("teddit")) {
-      // As of 2021-04-09, redirects for teddit images are nontrivial:
-      // - navigating to the image before ever navigating to its page causes
-      //   404 error (probably needs fix on teddit project)
-      // - some image links on teddit are very different
-      // Therefore, don't support redirecting image links for teddit.
-      return null;
-    } else {
-      return null;
-    }
-  } else if (url.host === "redd.it") {
-    if (
-      scribeInstance.includes("teddit") &&
-      !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)
-    ) {
-      // As of 2021-04-22, redirects for teddit redd.it/foo links don't work.
-      // It appears that adding "/comments" as a prefix works, so manually add
-      // that prefix if it is missing.  Even though redd.it/comments/foo links
-      // don't seem to work or exist, guard against affecting those kinds of
-      // paths.
-      //
-      // Note the difference between redd.it/comments/foo (doesn't work) and
-      // teddit.net/comments/foo (works).
-      return `${scribeInstance}/comments${url.pathname}${url.search}`;
-    }
+  if (url.host.split(".")[0] === "pbs" || url.host.split(".")[0] === "video") {
+    return `${
+      scribeInstance || commonHelper.getRandomInstance(scribeRandomPool)
+    }/pic/${encodeURIComponent(url.href)}`;
+  } else if (url.pathname.split("/").includes("tweets")) {
+    return `${
+      scribeInstance || commonHelper.getRandomInstance(scribeRandomPool)
+    }${url.pathname.replace("/tweets", "")}${url.search}`;
+  } else {
+    return `${
+      scribeInstance || commonHelper.getRandomInstance(scribeRandomPool)
+    }${url.pathname}${url.search}`;
   }
-  return `${scribeInstance}${url.pathname}${url.search}`;
 }
 
 function redirectSearchEngine(url, initiator) {
@@ -668,7 +663,7 @@ browser.webRequest.onBeforeRequest.addListener(
       };
     } else if (mediumDomains.includes(url.host)) {
       redirect = {
-        redirectUrl: redirectScribe(url, initiator, details.type),
+        redirectUrl: redirectMedium(url, initiator, details.type),
       };
     } else if (url.href.match(googleSearchRegex)) {
       redirect = {
diff --git a/src/pages/options/options.html b/src/pages/options/options.html
index 43db929d..bafff5f8 100644
--- a/src/pages/options/options.html
+++ b/src/pages/options/options.html
@@ -284,7 +284,7 @@
           <input
             id="scribe-instance"
             type="url"
-            placeholder="https://libredd.it"
+            placeholder="Random instance (none selected)"
           />
         </div>
       </section>
diff --git a/src/pages/options/options.js b/src/pages/options/options.js
index 938abd24..71bdc99e 100644
--- a/src/pages/options/options.js
+++ b/src/pages/options/options.js
@@ -73,6 +73,7 @@ let useFreeTube = document.getElementById("use-freetube");
 let nitterRandomPool = document.getElementById("nitter-random-pool");
 let invidiousRandomPool = document.getElementById("invidious-random-pool");
 let bibliogramRandomPool = document.getElementById("bibliogram-random-pool");
+let scribeRandomPool = document.getElementById("scribe-random-pool");
 let exceptions;
 
 window.browser = window.browser || window.chrome;
@@ -137,6 +138,7 @@ browser.storage.sync.get(
     "nitterRandomPool",
     "invidiousRandomPool",
     "bibliogramRandomPool",
+    "scribeRandomPool",
   ],
   (result) => {
     theme.value = result.theme || "";
@@ -184,6 +186,9 @@ browser.storage.sync.get(
     bibliogramRandomPool.value =
       result.bibliogramRandomPool ||
       commonHelper.filterInstances(bibliogramInstances);
+    scribeRandomPool.value =
+      result.scribeRandomPool ||
+      commonHelper.filterInstances(scribeInstances);
   }
 );
 
@@ -474,7 +479,13 @@ const bibliogramRandomPoolChange = debounce(() => {
     bibliogramRandomPool: bibliogramRandomPool.value,
   });
 }, 500);
-bibliogramRandomPool.addEventListener("input", bibliogramRandomPoolChange);
+
+const scribeRandomPoolChange = debounce(() => {
+  browser.storage.sync.set({
+    scribeRandomPool: scribeRandomPool.value,
+  });
+}, 500);
+scribeRandomPool.addEventListener("input", scribeRandomPoolChange);
 
 theme.addEventListener("change", (event) => {
   const value = event.target.options[theme.selectedIndex].value;