diff --git a/background.js b/background.js index 2fb698f..d5c8346 100644 --- a/background.js +++ b/background.js @@ -1,19 +1,56 @@ -const nitter = "https://nitter.net"; -const invidious = "https://invidio.us"; -const youtubeRegex = /((www|m)\.)?youtube(-nocookie)?\.com/ +'use strict'; + +const nitterDefault = 'https://nitter.net'; +const invidiousDefault = 'https://invidio.us'; +const youtubeRegex = /((www|m)\.)?youtube(-nocookie)?\.com/; +const pathRegex = /^https?:\/\/[^\/]+([\S\s]*)/; + +let nitterInstance; +let invidiousInstance; +let disableNitter; +let disableInvidious; + +chrome.storage.sync.get( + ['disableNitter', 'disableInvidious', 'nitterInstance', 'invidiousInstance'], + (result) => { + disableNitter = result.disableNitter; + disableInvidious = result.disableInvidious; + nitterInstance = result.nitterInstance || nitterDefault; + invidiousInstance = result.invidiousInstance || invidiousDefault; + } +); + +chrome.storage.onChanged.addListener(function (changes) { + if ('nitterInstance' in changes) { + nitterInstance = changes.nitterInstance.newValue || nitterDefault; + } + if ('invidiousInstance' in changes) { + invidiousInstance = changes.invidiousInstance.newValue || invidiousDefault; + } + if ('disableNitter' in changes) { + disableNitter = changes.disableNitter.newValue; + } + if ('disableInvidious' in changes) { + disableInvidious = changes.disableInvidious.newValue; + } +}); chrome.webRequest.onBeforeRequest.addListener( function (details) { if (details.url.match(youtubeRegex)) { - return { - redirectUrl: - invidious + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1] - }; + if (!disableInvidious) { + return { + redirectUrl: + invidiousInstance + details.url.match(pathRegex)[1] + }; + } } else { - return { - redirectUrl: - nitter + details.url.match(/^https?:\/\/[^\/]+([\S\s]*)/)[1] - }; + if (!disableNitter) { + return { + redirectUrl: + nitterInstance + details.url.match(pathRegex)[1] + }; + } } }, { diff --git a/manifest.json b/manifest.json index d314080..d2c20b0 100644 --- a/manifest.json +++ b/manifest.json @@ -1,12 +1,13 @@ { "name": "Privacy Redirect", "description": "Redirects Twitter & Youtube requests to privacy friendly alternatives (Nitter & Invidious).", - "version": "1.0.2", + "version": "1.1.1", "manifest_version": 2, "background": { "scripts": [ "background.js" - ] + ], + "persistent": true }, "icons": { "16": "images/icon16.png", @@ -39,5 +40,10 @@ "options_ui": { "page": "pages/options/options.html", "open_in_tab": false + }, + "browser_specific_settings": { + "gecko": { + "id": "{b7f9d2cd-d772-4302-8c3f-eb941af36f76}" + } } } \ No newline at end of file diff --git a/pages/options/options.html b/pages/options/options.html index f51f720..124aa4b 100644 --- a/pages/options/options.html +++ b/pages/options/options.html @@ -2,26 +2,46 @@
-