From b2e5f0c0991d0bca635d7b3cc6d95dc441933765 Mon Sep 17 00:00:00 2001 From: SimonBrazell Date: Fri, 20 Sep 2019 20:45:58 +1000 Subject: Initial commit --- background.js | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 background.js (limited to 'background.js') 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"] +); -- cgit 1.4.1