about summary refs log tree commit diff stats
path: root/background.js
blob: 2fb698f1f169a016da9f4cb8c6fe7577e719001e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
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"]
);