diff options
author | Simon Brazell <simon@brazell.com.au> | 2020-12-05 23:16:10 +1100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-12-05 23:16:10 +1100 |
commit | a075c449386d78003900fe2593f5a61c54ca95b0 (patch) | |
tree | aec3348778574872936f54237bd5fcc1220a8c08 | |
parent | Merge pull request #138 from austinhuang0131/patch-2 (diff) | |
parent | Updated background.js (diff) | |
download | libredirect-a075c449386d78003900fe2593f5a61c54ca95b0.zip |
Merge pull request #126 from aapl-yumi/patch-1
Add Search Engine redirects.
-rw-r--r-- | README.md | 9 | ||||
-rw-r--r-- | background.js | 34 | ||||
-rw-r--r-- | pages/options/options.html | 22 | ||||
-rw-r--r-- | pages/options/options.js | 7 | ||||
-rw-r--r-- | pages/popup/popup.html | 21 | ||||
-rw-r--r-- | pages/popup/popup.js | 7 |
6 files changed, 98 insertions, 2 deletions
diff --git a/README.md b/README.md index e42d1e83..820daebb 100644 --- a/README.md +++ b/README.md @@ -10,9 +10,9 @@ [](https://microsoftedge.microsoft.com/addons/detail/privacy-redirect/elnabkhcgpajchapppkhiaifkgikgihj) ## About -A web extension that redirects *Twitter, YouTube, Instagram & Google Maps* requests to privacy friendly alternatives - [Nitter](https://github.com/zedeus/nitter), [Invidious](https://github.com/iv-org/invidious), [FreeTube](https://github.com/FreeTubeApp/FreeTube), [Bibliogram](https://sr.ht/~cadence/bibliogram/) & [OpenStreetMap](https://www.openstreetmap.org/). +A web extension that redirects *Twitter, YouTube, Instagram, Google Maps & Non-Private Searches* requests to privacy friendly alternatives - [Nitter](https://github.com/zedeus/nitter), [Invidious](https://github.com/iv-org/invidious), [FreeTube](https://github.com/FreeTubeApp/FreeTube), [Bibliogram](https://sr.ht/~cadence/bibliogram/), [OpenStreetMap](https://www.openstreetmap.org/) & Private Search Engines like [DuckDuckGo](https://duckduckgo.com) and [Startpage](https://startpage.com). -It's possible to toggle all redirects on and off. The extension will default to using random instances if none are selected. If these instances are not working, you can try and set a custom instance from the list below. +It's possible to toggle all redirects on and off. The extension will default to using random instances if none are selected. If these instances are not working, you can try and set a custom instance from the list below. \*Instance for Search Engine redirect cannot be chosen at the moment. ### Custom instances Privacy Redirect allows setting custom instances, instances can be found here: @@ -20,6 +20,11 @@ Privacy Redirect allows setting custom instances, instances can be found here: - [Invidious instances](https://github.com/iv-org/invidious/wiki/Invidious-Instances) - [Bibliogram instances](https://git.sr.ht/~cadence/bibliogram-docs/tree/master/docs/Instances.md) - [OpenStreetMap tile servers](https://wiki.openstreetmap.org/wiki/Tile_servers) +- Private Search Engine list + - [DuckDuckGo](https://duckduckgo.com) + - [Startpage](https://startpage.com) + - [Qwant](https://www.qwant.com) + - [Mojeek](https://www.mojeek.com) ## Build diff --git a/background.js b/background.js index 0ab7b968..9fa766c1 100644 --- a/background.js +++ b/background.js @@ -132,12 +132,20 @@ const layers = { traffic: "S", // not implemented on OSM, default to standard. bicycling: "C", }; +const googleSearchRegex = /https?:\/\/(((www|maps)\.)?(google\.).*(\/search)|search\.(google\.).*)/; +const privateSearchEngine = [ + { link: "https://duckduckgo.com", q: "/" }, + { link: "https://startpage.com", q: "/search/" }, + { link: "https://www.qwant.com", q: "/" }, + { link: "https://www.mojeek.com", q: "/search" }, +]; let disableNitter; let disableInvidious; let disableBibliogram; let disableOsm; let disableOldReddit; +let disableSearchEngine; let nitterInstance; let invidiousInstance; let bibliogramInstance; @@ -175,6 +183,7 @@ browser.storage.sync.get( "disableBibliogram", "disableOsm", "disableOldReddit", + "disableSearchEngine", "alwaysProxy", "onlyEmbeddedVideo", "videoQuality", @@ -195,6 +204,7 @@ browser.storage.sync.get( disableBibliogram = result.disableBibliogram; disableOsm = result.disableOsm; disableOldReddit = result.disableOldReddit; + disableSearchEngine = result.disableSearchEngine; nitterInstance = result.nitterInstance; invidiousInstance = result.invidiousInstance; bibliogramInstance = result.bibliogramInstance; @@ -257,6 +267,9 @@ browser.storage.onChanged.addListener((changes) => { if ("disableOldReddit" in changes) { disableOldReddit = changes.disableOldReddit.newValue; } + if ("disableSearchEngine" in changes) { + disableSearchEngine = changes.disableSearchEngine.newValue; + } if ("alwaysProxy" in changes) { alwaysProxy = changes.alwaysProxy.newValue; } @@ -572,6 +585,23 @@ function redirectReddit(url, initiator, type) { return `${oldRedditView}${url.pathname}${url.search}`; } +function redirectSearchEngine(url, initiator) { + if (disableSearchEngine || isException(url, initiator)) { + return null; + } + + let searchEngine = getRandomInstance(privateSearchEngine); + let search = ""; + url.search + .slice(1) + .split("&") + .forEach(function (input) { + if (input.startsWith("q=")) search = input; + }); + console.log("search: ", search); + return `${searchEngine.link}${searchEngine.q}?${search}`; +} + browser.webRequest.onBeforeRequest.addListener( (details) => { const url = new URL(details.url); @@ -605,6 +635,10 @@ browser.webRequest.onBeforeRequest.addListener( redirect = { redirectUrl: redirectReddit(url, initiator, details.type), }; + } else if (url.href.match(googleSearchRegex)) { + redirect = { + redirectUrl: redirectSearchEngine(url, initiator), + }; } if (redirect && redirect.redirectUrl) { console.info( diff --git a/pages/options/options.html b/pages/options/options.html index c33dbb49..bd7cee7e 100644 --- a/pages/options/options.html +++ b/pages/options/options.html @@ -142,6 +142,28 @@ </tbody> </table> </section> + <section class="settings-block"> + <table class="option" aria-label="Toggle Search Engine redirects"> + <tbody> + <tr> + <td> + <h1 data-localise="__MSG_disableSearchEngine__"> + Search Engine Redirects + </h1> + </td> + <td> + <input + aria-hidden="true" + id="disable-searchEngine" + type="checkbox" + checked + /> + <label for="disable-searchEngine" class="checkbox-label"> </label> + </td> + </tr> + </tbody> + </table> + </section> <section class="settings-block"> <h1 data-localise="__MSG_nitterInstance__">Nitter Instance</h1> <div class="autocomplete"> diff --git a/pages/options/options.js b/pages/options/options.js index f0e5f0ab..3292567d 100644 --- a/pages/options/options.js +++ b/pages/options/options.js @@ -70,6 +70,7 @@ let disableInvidious = document.getElementById("disable-invidious"); let disableBibliogram = document.getElementById("disable-bibliogram"); let disableOsm = document.getElementById("disable-osm"); let disableOldReddit = document.getElementById("disable-old-reddit"); +let disableSearchEngine = document.getElementById("disable-searchEngine"); let alwaysProxy = document.getElementById("always-proxy"); let onlyEmbeddedVideo = document.getElementById("only-embed"); let videoQuality = document.getElementById("video-quality"); @@ -127,6 +128,7 @@ browser.storage.sync.get( "disableBibliogram", "disableOsm", "disableOldReddit", + "disableSearchEngine", "alwaysProxy", "onlyEmbeddedVideo", "videoQuality", @@ -157,6 +159,7 @@ browser.storage.sync.get( disableBibliogram.checked = !result.disableBibliogram; disableOsm.checked = !result.disableOsm; disableOldReddit.checked = !result.disableOldReddit; + disableSearchEngine.checked = !result.disableSearchEngine; alwaysProxy.checked = result.alwaysProxy; onlyEmbeddedVideo.checked = result.onlyEmbeddedVideo; videoQuality.value = result.videoQuality || ""; @@ -335,6 +338,10 @@ disableOldReddit.addEventListener("change", (event) => { browser.storage.sync.set({ disableOldReddit: !event.target.checked }); }); +disableSearchEngine.addEventListener("change", (event) => { + browser.storage.sync.set({ disableSearchEngine: !event.target.checked }); +}); + alwaysProxy.addEventListener("change", (event) => { browser.storage.sync.set({ alwaysProxy: event.target.checked }); }); diff --git a/pages/popup/popup.html b/pages/popup/popup.html index faf0deb8..af44b23e 100644 --- a/pages/popup/popup.html +++ b/pages/popup/popup.html @@ -138,6 +138,27 @@ </tbody> </table> </section> + + <section class="settings-block"> + <table class="option" aria-label="Toggle Search Engine redirects"> + <tbody> + <tr> + <td> + <h1 data-localise="__MSG_disableSearchEngine__">Search Engine Redirects</h1> + </td> + <td> + <input + aria-hidden="true" + id="disable-searchEngine" + type="checkbox" + checked + /> + <label for="disable-searchEngine" class="checkbox-label"></label> + </td> + </tr> + </tbody> + </table> + </section> <section class="settings-block"></section> diff --git a/pages/popup/popup.js b/pages/popup/popup.js index 34253702..6d4c3ff7 100644 --- a/pages/popup/popup.js +++ b/pages/popup/popup.js @@ -5,6 +5,7 @@ let disableInvidious = document.querySelector("#disable-invidious"); let disableBibliogram = document.querySelector("#disable-bibliogram"); let disableOsm = document.querySelector("#disable-osm"); let disableOldReddit = document.querySelector("#disable-old-reddit"); +let disableSearchEngine = document.querySelector("#disable-searchEngine"); let version = document.querySelector("#version"); window.browser = window.browser || window.chrome; @@ -16,6 +17,7 @@ browser.storage.sync.get( "disableBibliogram", "disableOsm", "disableOldReddit", + "disableSearchEngine", "theme", ], (result) => { @@ -25,6 +27,7 @@ browser.storage.sync.get( disableBibliogram.checked = !result.disableBibliogram; disableOsm.checked = !result.disableOsm; disableOldReddit.checked = !result.disableOldReddit; + disableSearchEngine.checked = !result.disableSearchEngine; } ); @@ -50,6 +53,10 @@ disableOldReddit.addEventListener("change", (event) => { browser.storage.sync.set({ disableOldReddit: !event.target.checked }); }); +disableSearchEngine.addEventListener("change", (event) => { + browser.storage.sync.set({ disableSearchEngine: !event.target.checked }); +}); + document.querySelector("#more-options").addEventListener("click", () => { browser.runtime.openOptionsPage(); }); |