about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorManeraKai <manerakai@protonmail.com>2022-03-03 00:46:29 +0300
committerManeraKai <manerakai@protonmail.com>2022-03-03 00:46:29 +0300
commit01020800a2051fc9cbcc94b42b03ee0660229ed0 (patch)
treebe60b7f3089d975c38a34ff666c3fca53fc1e18b /src
parentMerge branch 'master' of https://github.com/libredirect/libredirect (diff)
downloadlibredirect-01020800a2051fc9cbcc94b42b03ee0660229ed0.zip
Added alwaysUsePreferred to Twitter and Reddit
Diffstat (limited to 'src')
-rw-r--r--src/assets/javascripts/helpers/general.js (renamed from src/assets/javascripts/helpers/exceptions.js)37
-rw-r--r--src/assets/javascripts/helpers/reddit.js134
-rw-r--r--src/assets/javascripts/helpers/twitter.js33
-rw-r--r--src/assets/javascripts/helpers/youtube/youtube.js97
-rw-r--r--src/pages/background/background.js6
-rw-r--r--src/pages/options/general/general.html4
-rw-r--r--src/pages/options/general/general.js26
-rw-r--r--src/pages/options/reddit/reddit.js1
-rw-r--r--src/pages/options/youtube/youtube.html5
-rw-r--r--src/pages/options/youtube/youtube.js6
10 files changed, 215 insertions, 134 deletions
diff --git a/src/assets/javascripts/helpers/exceptions.js b/src/assets/javascripts/helpers/general.js
index 7c6e4798..fa911b4f 100644
--- a/src/assets/javascripts/helpers/exceptions.js
+++ b/src/assets/javascripts/helpers/general.js
@@ -1,10 +1,19 @@
 "use strict";
 window.browser = window.browser || window.chrome;
 
+let alwaysUsePreferred;
+const getAlwaysUsePreferred = () => alwaysUsePreferred;
+function setAlwaysUsePreferred(val) {
+    alwaysUsePreferred = val;
+    browser.storage.local.set({ alwaysUsePreferred })
+    console.log("alwaysUsePreferred: ", alwaysUsePreferred)
+}
+
 let exceptions = {
     "url": [],
     "regex": [],
 };
+
 const getExceptions = () => exceptions;
 function setExceptions(val) {
     exceptions = val;
@@ -12,15 +21,6 @@ function setExceptions(val) {
     console.log("exceptions: ", val)
 }
 
-async function init() {
-    return new Promise((resolve) => {
-        browser.storage.local.get("exceptions", (result) => {
-            if (result.exceptions) exceptions = result.exceptions;
-            resolve();
-        });
-    })
-}
-
 function isException(url) {
     for (const item of exceptions.url) {
         console.log(item, `${url.protocol}//${url.host}`)
@@ -31,10 +31,29 @@ function isException(url) {
     return false;
 }
 
+async function init() {
+    return new Promise(
+        resolve => browser.storage.local.get(
+            [
+                "exceptions",
+                "alwaysUsePreferred"
+            ],
+            r => { // r = result
+                if (r.exceptions) exceptions = r.exceptions;
+                alwaysUsePreferred = r.alwaysUsePreferred ?? false;
+                resolve();
+            }
+        )
+    )
+}
+
 export default {
     getExceptions,
     setExceptions,
 
+    getAlwaysUsePreferred,
+    setAlwaysUsePreferred,
+
     isException,
     init,
 }
\ No newline at end of file
diff --git a/src/assets/javascripts/helpers/reddit.js b/src/assets/javascripts/helpers/reddit.js
index 268c721d..db8820eb 100644
--- a/src/assets/javascripts/helpers/reddit.js
+++ b/src/assets/javascripts/helpers/reddit.js
@@ -3,13 +3,13 @@ window.browser = window.browser || window.chrome;
 import commonHelper from './common.js'
 
 const targets = [
-  "reddit.com",
-  "www.reddit.com",
-  "np.reddit.com",
-  "new.reddit.com",
-  "amp.reddit.com",
-  "i.redd.it",
-  "redd.it",
+  /^https?:\/\/reddit\.com/,
+  /^https?:\/\/www\.reddit\.com/,
+  /^https?:\/\/np\.reddit\.com/,
+  /^https?:\/\/new\.reddit\.com/,
+  /^https?:\/\/amp\.reddit\.com/,
+  /^https?:\/\/i\.redd\.it/,
+  /^https?:\/\/redd\.it/,
 ];
 let redirects = {
   // modern UI
@@ -184,10 +184,6 @@ function setProtocol(val) {
   console.log("redditProtocol: ", val)
 }
 
-function isReddit(url,) {
-
-}
-
 let bypassWatchOnReddit;
 const getBypassWatchOnReddit = () => bypassWatchOnReddit;
 function setBypassWatchOnReddit(val) {
@@ -196,9 +192,61 @@ function setBypassWatchOnReddit(val) {
   console.log("bypassWatchOnReddit: ", bypassWatchOnReddit)
 }
 
+let alwaysUsePreferred;
+
+
+// https://libreddit.exonip.de/vid/1mq8d0ma3yk81/720.mp4
+// https://libreddit.exonip.de/img/4v3t1vgvrzk81.png
+
+// https://teddit.net/vids/1mq8d0ma3yk81.mp4
+// https://teddit.net/pics/w:null_4v3t1vgvrzk81.png
+
+
+// redd.it/t5379n
+// https://v.redd.it/z08avb339n801/DASH_1_2_M
+// https://i.redd.it/bfkhs659tzk81.jpg
+
 function redirect(url, type, initiator) {
   if (disableReddit) return null;
 
+  let protocolHost = `${url.protocol}//${url.host}`;
+
+  let isTeddit = [
+    ...redirects.teddit.normal,
+    ...redirects.teddit.tor
+  ].includes(protocolHost);
+
+  let isCheckedTeddit = [
+    ...tedditNormalRedirectsChecks,
+    ...tedditNormalCustomRedirects,
+    ...tedditTorRedirectsChecks,
+    ...tedditTorCustomRedirects,
+  ].includes(protocolHost);
+
+  let isLibreddit = [
+    ...redirects.libreddit.normal,
+    ...redirects.libreddit.tor
+  ].includes(protocolHost);
+
+  let isCheckedLibreddit = [
+    ...libredditNormalRedirectsChecks,
+    ...libredditNormalCustomRedirects,
+    ...libredditTorRedirectsChecks,
+    ...libredditTorCustomRedirects,
+  ].includes(protocolHost)
+
+  if (
+    alwaysUsePreferred && frontend == 'teddit' &&
+    (isTeddit || isLibreddit) && !isCheckedTeddit
+  ) return changeInstance(url);
+
+  if (
+    alwaysUsePreferred && frontend == 'libreddit' &&
+    (isTeddit || isLibreddit) && !isCheckedLibreddit
+  ) return changeInstance(url);
+
+  if (!targets.some((rx) => rx.test(url.href))) return null;
+
   if (
     bypassWatchOnReddit &&
     initiator &&
@@ -211,20 +259,15 @@ function redirect(url, type, initiator) {
       ...redirects.teddit.tor,
       ...tedditNormalCustomRedirects,
       ...tedditTorCustomRedirects,
-      ].includes(initiator.origin) ||
-      targets.includes(initiator.host)
+      ].includes(initiator.origin)
     )
   ) return 'BYPASSTAB';
 
-  if ((!targets.includes(url.host))) return null;
-
   if (type !== "main_frame" || url.pathname.match(bypassPaths)) return null;
 
-  if (frontend == 'old') {
-    if (url.host === "i.redd.it") return null;
-
+  if (frontend == 'old' && url.host !== "i.redd.it")
     return `${redirects.desktop}${url.pathname}${url.search}`;
-  }
+
   let libredditInstancesList;
   let tedditInstancesList;
   if (protocol == 'normal') {
@@ -236,31 +279,28 @@ function redirect(url, type, initiator) {
   }
 
   if (url.host === "i.redd.it") {
-    if (libredditInstancesList.length === 0) return null;
-    let libredditRandomInstance = commonHelper.getRandomInstance(libredditInstancesList);
-    // 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 `${libredditRandomInstance}/img${url.pathname}${url.search}`;
+    if (frontend == 'teddit') {
+      if (tedditInstancesList.length === 0) return null;
+      let tedditRandomInstance = commonHelper.getRandomInstance(tedditInstancesList);
+      return `${tedditRandomInstance}/pics/w:null_${url.pathname.substring(1)}${url.search}`;
+    }
+    if (frontend == 'libreddit') {
+      if (libredditInstancesList.length === 0) return null;
+      let libredditRandomInstance = commonHelper.getRandomInstance(libredditInstancesList);
+      return `${libredditRandomInstance}/img${url.pathname}${url.search}`;
+    }
   }
   else if (url.host === "redd.it") {
-    if (frontend == 'libreddit') {
+    if (frontend == 'libreddit' && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) {
       if (libredditInstancesList.length === 0) return null;
       let libredditRandomInstance = commonHelper.getRandomInstance(libredditInstancesList);
-      return `${libredditRandomInstance}${url.pathname}${url.search}`;
+      // https://redd.it/foo => https://libredd.it/comments/foo
+      return `${libredditRandomInstance}/comments${url.pathname}${url.search}`;
     }
     if (frontend == 'teddit' && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) {
       if (tedditInstancesList.length === 0) return null;
       let tedditRandomInstance = commonHelper.getRandomInstance(tedditInstancesList);
-      // 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).
+      // https://redd.it/foo => https://teddit.net/comments/foo
       return `${tedditRandomInstance}/comments${url.pathname}${url.search}`;
     }
   }
@@ -279,6 +319,16 @@ function redirect(url, type, initiator) {
 function changeInstance(url) {
   let protocolHost = `${url.protocol}//${url.host}`;
 
+  let isTeddit = [
+    ...redirects.teddit.normal,
+    ...redirects.teddit.tor
+  ].includes(protocolHost);
+
+  let isLibreddit = [
+    ...redirects.libreddit.normal,
+    ...redirects.libreddit.tor
+  ].includes(protocolHost);
+
   let redditList = [
     ...redirects.libreddit.normal,
     ...redirects.libreddit.tor,
@@ -299,20 +349,21 @@ function changeInstance(url) {
   if (frontend == 'libreddit') {
     if (protocol == 'normal') instancesList = [...libredditNormalRedirectsChecks, ...libredditNormalCustomRedirects];
     else if (protocol == 'tor') instancesList = [...libredditTorRedirectsChecks, ...libredditTorCustomRedirects];
+    if (isTeddit) url.pathname = url.pathname.replace("/pics/w:null_", "/img/");
   }
   else if (frontend == 'teddit') {
     if (protocol == 'normal') instancesList = [...tedditNormalRedirectsChecks, ...tedditNormalCustomRedirects];
     else if (protocol == 'tor') instancesList = [...tedditTorRedirectsChecks, ...tedditTorCustomRedirects];
+    if (isLibreddit) url.pathname = url.pathname.replace("/img/", "/pics/w:null_");
   }
 
-  console.log("instancesList", instancesList);
   let index = instancesList.indexOf(protocolHost);
   if (index > -1) instancesList.splice(index, 1);
-
   if (instancesList.length === 0) return null;
 
   let randomInstance = commonHelper.getRandomInstance(instancesList);
-  return randomInstance;
+
+  return `${randomInstance}${url.pathname}${url.search}`;
 }
 
 async function init() {
@@ -337,6 +388,8 @@ async function init() {
 
           "redditProtocol",
           "bypassWatchOnReddit",
+
+          "alwaysUsePreferred",
         ], (result) => {
           disableReddit = result.disableReddit ?? false;
           protocol = result.redditProtocol ?? 'normal';
@@ -344,6 +397,8 @@ async function init() {
 
           bypassWatchOnReddit = result.bypassWatchOnReddit ?? true;
 
+          alwaysUsePreferred = result.alwaysUsePreferred ?? true;
+
           redirects.teddit = dataJson.teddit;
           if (result.redditRedirects) redirects = result.redditRedirects;
 
@@ -408,7 +463,6 @@ export default {
   setTedditTorCustomRedirects,
 
   redirect,
-  isReddit,
   init,
   changeInstance,
 };
diff --git a/src/assets/javascripts/helpers/twitter.js b/src/assets/javascripts/helpers/twitter.js
index 3d0fc2e3..d389f0e7 100644
--- a/src/assets/javascripts/helpers/twitter.js
+++ b/src/assets/javascripts/helpers/twitter.js
@@ -102,7 +102,23 @@ function setBypassWatchOnTwitter(val) {
   console.log("bypassWatchOnTwitter: ", bypassWatchOnTwitter)
 }
 
+let alwaysUsePreferred;
+
 function redirect(url, initiator) {
+  let protocolHost = `${url.protocol}//${url.host}`;
+  let isNitter = [
+    ...redirects.nitter.normal,
+    ...redirects.nitter.tor
+  ].includes(protocolHost);
+
+  let isCheckedNitter = [
+    ...nitterNormalRedirectsChecks,
+    ...nitterNormalCustomRedirects,
+    ...nitterTorRedirectsChecks,
+    ...nitterTorCustomRedirects
+  ].includes(protocolHost);
+
+  if (alwaysUsePreferred && isNitter && !isCheckedNitter) return changeInstance(url);
 
   if (disable) return null;
 
@@ -112,13 +128,13 @@ function redirect(url, initiator) {
 
   if (
     bypassWatchOnTwitter &&
-    initiator && (
-      [...redirects.nitter.normal,
-      ...redirects.nitter.tor,
-      ...nitterTorCustomRedirects,
-      ...nitterNormalCustomRedirects
-      ].includes(initiator.origin)
-    )
+    initiator &&
+    [...redirects.nitter.normal,
+    ...redirects.nitter.tor,
+    ...nitterTorCustomRedirects,
+    ...nitterNormalCustomRedirects
+    ].includes(initiator.origin)
+
   ) return 'BYPASSTAB';
 
   let instancesList;
@@ -179,6 +195,7 @@ async function init() {
           "nitterTorRedirectsChecks",
           "nitterTorCustomRedirects",
           "twitterProtocol",
+          "alwaysUsePreferred",
         ],
         (result) => {
           disable = result.disableTwitter ?? false;
@@ -187,6 +204,8 @@ async function init() {
 
           bypassWatchOnTwitter = result.bypassWatchOnTwitter ?? true;
 
+          alwaysUsePreferred = result.alwaysUsePreferred ?? true;
+
           redirects.nitter = dataJson.nitter;
           if (result.twitterRedirects) redirects = result.twitterRedirects;
 
diff --git a/src/assets/javascripts/helpers/youtube/youtube.js b/src/assets/javascripts/helpers/youtube/youtube.js
index d52cf949..b33c258b 100644
--- a/src/assets/javascripts/helpers/youtube/youtube.js
+++ b/src/assets/javascripts/helpers/youtube/youtube.js
@@ -233,14 +233,6 @@ function setPersistInvidiousPrefs(val) {
   console.log("persistInvidiousPrefs: ", persistInvidiousPrefs)
 }
 
-let alwaysusePreferred;
-const getAlwaysusePreferred = () => alwaysusePreferred;
-function setAlwaysusePreferred(val) {
-  alwaysusePreferred = val;
-  browser.storage.local.set({ alwaysusePreferred })
-  console.log("alwaysusePreferred: ", alwaysusePreferred)
-}
-
 let bypassWatchOnYoutube;
 const getBypassWatchOnYoutube = () => bypassWatchOnYoutube;
 function setBypassWatchOnYoutube(val) {
@@ -271,57 +263,54 @@ function isException(url) {
   return false;
 }
 
+
+let alwaysUsePreferred;
 function redirect(url, details, initiator) {
   if (disable) return null;
 
-  let isTargets = targets.some((rx) => rx.test(url.href));
   let protocolHost = `${url.protocol}//${url.host}`;
 
-  let isInvidious = [...redirects.invidious.normal, ...redirects.invidious.tor].includes(protocolHost);
-  if (isInvidious) {
-    let myInvidiousInstances = [
-      ...invidiousNormalRedirectsChecks,
-      ...invidiousNormalCustomRedirects,
+  let isInvidious = [
+    ...redirects.invidious.normal,
+    ...redirects.invidious.tor
+  ].includes(protocolHost);
 
-      ...invidiousTorRedirectsChecks,
-      ...invidiousTorCustomRedirects,
-    ];
-    for (const item of myInvidiousInstances) if (item == protocolHost) isInvidious = false;
-  }
+  let isCheckedInvidious = [
+    ...invidiousNormalRedirectsChecks,
+    ...invidiousNormalCustomRedirects,
+    ...invidiousTorRedirectsChecks,
+    ...invidiousTorCustomRedirects,
+  ].includes(protocolHost);
 
-  let isPiped = [...redirects.piped.normal, ...redirects.piped.tor].includes(protocolHost);
-  if (isPiped) {
-    let myPipedInstances = [
-      ...pipedNormalRedirectsChecks,
-      ...pipedNormalCustomRedirects,
+  let isPiped = [
+    ...redirects.piped.normal,
+    ...redirects.piped.tor
+  ].includes(protocolHost);
 
-      ...pipedTorRedirectsChecks,
-      ...pipedTorCustomRedirects,
-    ];
-    for (const item of myPipedInstances) if (item == protocolHost) isPiped = false;
-  }
+  let isCheckedPiped = [
+    ...pipedNormalRedirectsChecks,
+    ...pipedNormalCustomRedirects,
+    ...pipedTorRedirectsChecks,
+    ...pipedTorCustomRedirects,
+  ].includes(protocolHost)
 
-  if (frontend == 'invidious') {
-    if (alwaysusePreferred) {
-      if (!(isTargets | redirects.piped.normal.includes(protocolHost) | isInvidious)) return null;
-    }
-    else {
-      if (!(isTargets | isPiped)) return null;
-    }
-  }
-  if (frontend == 'piped') {
-    if (alwaysusePreferred) {
-      if (!(isTargets | isPiped | redirects.invidious.normal.includes(protocolHost))) return null;
-    }
-    else {
-      if (!(isTargets | isInvidious)) return null;
-    }
-  }
-  else
-    if (!isTargets) return null;
+  if (
+    alwaysUsePreferred && frontend == 'invidious' &&
+    (isInvidious || isPiped) && !isCheckedInvidious
+  ) return changeInstance(url);
+
+  if (
+    alwaysUsePreferred && frontend == 'piped' &&
+    (isInvidious || isPiped) && !isCheckedPiped
+  ) return changeInstance(url);
 
+  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))) {
+  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;
   }
@@ -366,11 +355,10 @@ function redirect(url, details, initiator) {
     let instancesList;
     if (protocol == 'normal') instancesList = [...invidiousNormalRedirectsChecks, ...invidiousNormalCustomRedirects];
     else if (protocol == 'tor') instancesList = [...invidiousTorRedirectsChecks, ...invidiousTorCustomRedirects];
-
     if (instancesList.length === 0) return null;
     let randomInstance = commonHelper.getRandomInstance(instancesList);
 
-    return `${randomInstance}${url.pathname.replace("/shorts/", "/watch?v=")}${url.search}`;
+    return `${randomInstance}${url.pathname}${url.search}`;
 
   } else if (
     frontend == 'piped' ||
@@ -389,7 +377,7 @@ function redirect(url, details, initiator) {
     if (instancesList.length === 0) return null;
     let randomInstance = commonHelper.getRandomInstance(instancesList);
 
-    return `${randomInstance}${url.pathname.replace("/shorts/", "/watch?v=")}${url.search}`;
+    return `${randomInstance}${url.pathname}${url.search}`;
   }
   return 'CANCEL';
 }
@@ -612,7 +600,7 @@ async function init() {
 
           "pipedTorRedirectsChecks",
           "pipedTorCustomRedirects",
-          "alwaysusePreferred",
+          "alwaysUsePreferred",
           "youtubeEmbedFrontend",
 
           "youtubeProtocol",
@@ -653,7 +641,7 @@ async function init() {
 
           persistInvidiousPrefs = result.persistInvidiousPrefs ?? false;
 
-          alwaysusePreferred = result.alwaysusePreferred ?? true;
+          alwaysUsePreferred = result.alwaysUsePreferred ?? true;
 
           bypassWatchOnYoutube = result.bypassWatchOnYoutube ?? true;
 
@@ -746,9 +734,6 @@ export default {
   getPipedTorCustomRedirects,
   setPipedTorCustomRedirects,
 
-  getAlwaysusePreferred,
-  setAlwaysusePreferred,
-
   getExceptions,
   setExceptions,
   isException,
diff --git a/src/pages/background/background.js b/src/pages/background/background.js
index 3211e1c7..c35e240c 100644
--- a/src/pages/background/background.js
+++ b/src/pages/background/background.js
@@ -11,7 +11,7 @@ import wikipediaHelper from "../../assets/javascripts/helpers/wikipedia.js";
 import mediumHelper from "../../assets/javascripts/helpers/medium.js";
 import imgurHelper from "../../assets/javascripts/helpers/imgur.js";
 import tiktokHelper from "../../assets/javascripts/helpers/tiktok.js";
-import exceptionsHelper from "../../assets/javascripts/helpers/exceptions.js";
+import generalHelper from "../../assets/javascripts/helpers/general.js";
 import youtubeMusicHelper from "../../assets/javascripts/helpers/youtubeMusic.js";
 
 window.browser = window.browser || window.chrome;
@@ -29,7 +29,7 @@ async function wholeInit() {
   wikipediaHelper.init()
   imgurHelper.init()
   tiktokHelper.init()
-  exceptionsHelper.init()
+  generalHelper.init()
 
 }
 wholeInit();
@@ -73,7 +73,7 @@ browser.webRequest.onBeforeRequest.addListener(
 
     if (wikipediaHelper.isWikipedia(url, initiator)) newUrl = wikipediaHelper.redirect(url);
 
-    if (exceptionsHelper.isException(url, initiator)) newUrl = null;
+    if (generalHelper.isException(url, initiator)) newUrl = null;
 
     if (BYPASSTABs.includes(details.tabId)) newUrl = null;
 
diff --git a/src/pages/options/general/general.html b/src/pages/options/general/general.html
index 8b9e401d..ddfa931d 100644
--- a/src/pages/options/general/general.html
+++ b/src/pages/options/general/general.html
@@ -96,6 +96,10 @@
       </select>
     </div>
 
+    <div class="some-block option-block">
+      <h4>Always use Preferred Instances</h4>
+      <input id="always-use-preferred" type="checkbox" checked />
+    </div>
 
     <div class="some-block option-block">
       <h4>Exceptions</h4>
diff --git a/src/pages/options/general/general.js b/src/pages/options/general/general.js
index 5d4c0307..344af4aa 100644
--- a/src/pages/options/general/general.js
+++ b/src/pages/options/general/general.js
@@ -2,7 +2,7 @@
 window.browser = window.browser || window.chrome;
 
 import commonHelper from "../../../assets/javascripts/helpers/common.js";
-import exceptionsHelper from "../../../assets/javascripts/helpers/exceptions.js";
+import generalHelper from "../../../assets/javascripts/helpers/general.js";
 
 let themeElement = document.getElementById("theme");
 
@@ -44,32 +44,42 @@ function exportSettings() {
 }
 exportSettings();
 
+browser.storage.onChanged.addListener(exportSettings);
+
 let importSettingsElement = document.getElementById("import-settings");
 importSettingsElement.addEventListener("change",
-  _ => {
+  () => {
     let file = importSettingsElement.files[0];
     const reader = new FileReader();
     reader.readAsText(file);
     reader.onload = () => browser.storage.local.set({ ...JSON.parse(reader.result) })
     reader.onerror = error => reject(error);
-    exportSettings();
+    location.reload();
   }
 );
 
 let resetSettingsElement = document.getElementById("reset-settings");
+
 resetSettingsElement.addEventListener("click",
   () => {
     console.log("reset");
     browser.storage.local.clear();
-    exportSettings();
+    location.reload();
   }
 );
 
+let alwaysUsePreferredElement = document.getElementById("always-use-preferred")
+alwaysUsePreferredElement.addEventListener("change",
+  event => generalHelper.setAlwaysUsePreferred(event.target.checked)
+);
+
 let nameCustomInstanceInput = document.getElementById("exceptions-custom-instance");
 let instanceTypeElement = document.getElementById("exceptions-custom-instance-type");
 let instanceType = "url"
 
-exceptionsHelper.init().then(() => {
+generalHelper.init().then(() => {
+  alwaysUsePreferredElement.checked = generalHelper.getAlwaysUsePreferred();
+  console.log("generalHelper.getAlwaysUsePreferred()");
   instanceTypeElement.addEventListener("change",
     (event) => {
       instanceType = event.target.options[instanceTypeElement.selectedIndex].value
@@ -83,7 +93,7 @@ exceptionsHelper.init().then(() => {
       }
     }
   )
-  let exceptionsCustomInstances = exceptionsHelper.getExceptions();
+  let exceptionsCustomInstances = generalHelper.getExceptions();
   function calcExceptionsCustomInstances() {
     console.log("exceptionsCustomInstances", exceptionsCustomInstances)
     document.getElementById("exceptions-custom-checklist").innerHTML =
@@ -112,7 +122,7 @@ exceptionsHelper.init().then(() => {
             if (index > -1)
               exceptionsCustomInstances.regex.splice(index, 1);
           }
-          exceptionsHelper.setExceptions(exceptionsCustomInstances);
+          generalHelper.setExceptions(exceptionsCustomInstances);
           calcExceptionsCustomInstances();
         });
     }
@@ -133,7 +143,7 @@ exceptionsHelper.init().then(() => {
       if (val.trim() != '' && !exceptionsCustomInstances.regex.includes(val)) exceptionsCustomInstances.regex.push(val)
     }
     if (val) {
-      exceptionsHelper.setExceptions(exceptionsCustomInstances);
+      generalHelper.setExceptions(exceptionsCustomInstances);
       console.log("exceptionsCustomInstances", exceptionsCustomInstances)
       nameCustomInstanceInput.value = '';
     }
diff --git a/src/pages/options/reddit/reddit.js b/src/pages/options/reddit/reddit.js
index 8e435675..5feddec6 100644
--- a/src/pages/options/reddit/reddit.js
+++ b/src/pages/options/reddit/reddit.js
@@ -78,6 +78,7 @@ redditHelper.init().then(() => {
     protocolElement.value = protocol;
     changeProtocolSettings(protocol);
 
+
     commonHelper.processDefaultCustomInstances(
         'libreddit',
         'normal',
diff --git a/src/pages/options/youtube/youtube.html b/src/pages/options/youtube/youtube.html
index 5608975d..e0774c0a 100644
--- a/src/pages/options/youtube/youtube.html
+++ b/src/pages/options/youtube/youtube.html
@@ -137,11 +137,6 @@
       </div>
 
       <div class="some-block option-block">
-        <h4>Always use Preferred Instances</h4>
-        <input id="always-use-preferred" type="checkbox" checked />
-      </div>
-
-      <div class="some-block option-block">
         <h4>Bypass Watch On YouTube</h4>
         <input id="bypass-watch-on-youtube" type="checkbox" checked />
       </div>
diff --git a/src/pages/options/youtube/youtube.js b/src/pages/options/youtube/youtube.js
index cc87edbe..168a9d30 100644
--- a/src/pages/options/youtube/youtube.js
+++ b/src/pages/options/youtube/youtube.js
@@ -100,11 +100,6 @@ OnlyEmbeddedVideoElement.addEventListener("change",
     event => youtubeHelper.setOnlyEmbeddedVideo(event.target.options[OnlyEmbeddedVideoElement.selectedIndex].value)
 );
 
-let alwaysUsePreferredElement = document.getElementById("always-use-preferred")
-alwaysUsePreferredElement.addEventListener("change",
-    event => youtubeHelper.setAlwaysusePreferred(event.target.checked)
-);
-
 let bypassWatchOnYoutubeElement = document.getElementById("bypass-watch-on-youtube")
 bypassWatchOnYoutubeElement.addEventListener("change",
     event => youtubeHelper.setBypassWatchOnYoutube(event.target.checked)
@@ -145,7 +140,6 @@ youtubeHelper.init().then(() => {
     volumeElement.value = youtubeHelper.getVolume();
     volumeValueElement.textContent = `${youtubeHelper.getVolume()}%`;
     OnlyEmbeddedVideoElement.value = youtubeHelper.getOnlyEmbeddedVideo();
-    alwaysUsePreferredElement.checked = youtubeHelper.getAlwaysusePreferred();
     bypassWatchOnYoutubeElement.checked = youtubeHelper.getBypassWatchOnYoutube();
     autoplayElement.value = youtubeHelper.getAutoplay();
     let frontend = youtubeHelper.getFrontend();