about summary refs log tree commit diff stats
path: root/background.js
diff options
context:
space:
mode:
authorSimon Brazell <simon.brazell@gmail.com>2019-09-20 20:45:58 +1000
committerSimon Brazell <simon.brazell@gmail.com>2019-09-20 20:45:58 +1000
commit565d1203429c6291fe35992811303b6b3254e8cf (patch)
treee196653cf79c68be8804d096b94f9f7394a25dc3 /background.js
downloadlibredirect-565d1203429c6291fe35992811303b6b3254e8cf.zip
Initial commit
Diffstat (limited to 'background.js')
-rw-r--r--background.js42
1 files changed, 42 insertions, 0 deletions
diff --git a/background.js b/background.js
new file mode 100644
index 00000000..2fb698f1
--- /dev/null
+++ b/background.js
@@ -0,0 +1,42 @@
+const nitter = "https://nitter.net";
+const invidious = "https://invidio.us";
+const youtubeRegex = /((www|m)\.)?youtube(-nocookie)?\.com/
+
+chrome.webRequest.onBeforeRequest.addListener(
+  function (details) {
+    if (details.url.match(youtubeRegex)) {
+      return {
+        redirectUrl:
+          invidious + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1]
+      };
+    } else {
+      return {
+        redirectUrl:
+          nitter + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1]
+      };
+    }
+  },
+  {
+    urls: [
+      "*://twitter.com/*",
+      "*://www.twitter.com/*",
+      "*://mobile.twitter.com/*",
+      "*://youtube.com/*",
+      "*://www.youtube.com/*",
+      "*://youtube-nocookie.com/*",
+      "*://www.youtube-nocookie.com/*",
+      "*://m.youtube.com/"
+    ],
+    types: [
+      "main_frame",
+      "sub_frame",
+      "stylesheet",
+      "script",
+      "image",
+      "object",
+      "xmlhttprequest",
+      "other"
+    ]
+  },
+  ["blocking"]
+);