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 @@ - My Test Extension Options + + + + + Privacy Redirect Options - Favorite color: - +
+
+

Nitter Redirects

+   + +
+
- +
+
+

Invidious Redirects

+   + +
+
+ +
+

Nitter Instance

+ +

Invidious Instance

+ +
+ + + + -
- \ No newline at end of file diff --git a/pages/options/options.js b/pages/options/options.js new file mode 100644 index 0000000..b5c097d --- /dev/null +++ b/pages/options/options.js @@ -0,0 +1,26 @@ +'use strict'; + +let disableNitter = document.querySelector('#disableNitter'); +let disableInvidious = document.querySelector('#disableInvidious'); +let nitterInstance = document.querySelector('#nitterInstance'); +let invidiousInstance = document.querySelector('#invidiousInstance'); + +chrome.storage.sync.get( + ['disableNitter', 'disableInvidious', 'nitterInstance', 'invidiousInstance'], + (result) => { + disableNitter.checked = !result.disableNitter; + disableInvidious.checked = !result.disableInvidious; + nitterInstance.value = result.nitterInstance || ''; + invidiousInstance.value = result.invidiousInstance || ''; + } +); + +document.querySelector('#save').addEventListener('click', () => { + chrome.storage.sync.set({ + disableNitter: !disableNitter.checked, + disableInvidious: !disableInvidious.checked, + nitterInstance: nitterInstance.value, + invidiousInstance: invidiousInstance.value + }); + window.close(); +}); \ No newline at end of file diff --git a/pages/popup/popup.html b/pages/popup/popup.html index 0e28a99..889ffcd 100644 --- a/pages/popup/popup.html +++ b/pages/popup/popup.html @@ -5,7 +5,7 @@ - + @@ -14,26 +14,24 @@ Privacy Redirect logo - Version: 1.0.2 + Version: 1.1.1 -
+
-

Nitter Redirects

- -
-
+
-

Invidious Redirects

- -
@@ -43,6 +41,7 @@ + \ No newline at end of file diff --git a/pages/popup/popup.js b/pages/popup/popup.js index 0dddb49..2837cdb 100644 --- a/pages/popup/popup.js +++ b/pages/popup/popup.js @@ -1,4 +1,25 @@ -document.querySelector('#options').addEventListener('click', function () { +'use strict'; + +let disableNitter = document.querySelector('#disableNitter'); +let disableInvidious = document.querySelector('#disableInvidious'); + +chrome.storage.sync.get( + ['disableNitter', 'disableInvidious'], + (result) => { + disableNitter.checked = !result.disableNitter; + disableInvidious.checked = !result.disableInvidious; + } +); + +disableNitter.addEventListener('change', (event) => { + chrome.storage.sync.set({ disableNitter: !event.target.checked }); +}); + +disableInvidious.addEventListener('change', (event) => { + chrome.storage.sync.set({ disableInvidious: !event.target.checked }); +}); + +document.querySelector('#options').addEventListener('click', () => { if (chrome.runtime.openOptionsPage) { chrome.runtime.openOptionsPage(); } else { diff --git a/pages/popup/popup.css b/pages/styles.css similarity index 95% rename from pages/popup/popup.css rename to pages/styles.css index eebab8e..5a23352 100644 --- a/pages/popup/popup.css +++ b/pages/styles.css @@ -73,11 +73,17 @@ footer a.button { } /* Elements */ + +input[type=url] { + width: 100%; + margin-bottom: 5px; +} + input[type=checkbox] { opacity: 0; } -label { +.checkbox-label { background: grey; border-radius: 25px; color: var(--text-main); @@ -91,7 +97,7 @@ label { width: 50px; } -label:after { +.checkbox-label:after { background: #fff; border-radius: 90px; content: '';