From df07b8a7f43f0f68c0125c39abf6aca37d767d54 Mon Sep 17 00:00:00 2001 From: Ngô Ngọc Đức Huy Date: Mon, 11 Oct 2021 10:04:25 +0700 Subject: Add redirect from Medium to Scribe Multiple Medium domains would be redirected to two known Scribe instances: scribe.rip scribe.nixnet.services --- src/pages/options/options.html | 32 ++++++++++++++++++++++++++++++++ src/pages/options/options.js | 22 ++++++++++++++++++++++ 2 files changed, 54 insertions(+) (limited to 'src/pages/options') diff --git a/src/pages/options/options.html b/src/pages/options/options.html index 65f1e9ab..43db929d 100644 --- a/src/pages/options/options.html +++ b/src/pages/options/options.html @@ -141,6 +141,28 @@ + +
+ + + + + + + +
+

+ Scribe Redirects +

+
+   + +
@@ -256,6 +278,16 @@ /> +
+

Scribe Instance

+
+ +
+

Search Engine Instance

diff --git a/src/pages/options/options.js b/src/pages/options/options.js index 91e7ac05..938abd24 100644 --- a/src/pages/options/options.js +++ b/src/pages/options/options.js @@ -6,6 +6,7 @@ import youtubeHelper from "../../assets/javascripts/helpers/youtube.js"; import instagramHelper from "../../assets/javascripts/helpers/instagram.js"; import mapsHelper from "../../assets/javascripts/helpers/google-maps.js"; import redditHelper from "../../assets/javascripts/helpers/reddit.js"; +import mediumHelper from "../../assets/javascripts/helpers/medium.js"; import searchHelper from "../../assets/javascripts/helpers/google-search.js"; import googleTranslateHelper from "../../assets/javascripts/helpers/google-translate.js"; import wikipediaHelper from "../../assets/javascripts/helpers/wikipedia.js"; @@ -15,6 +16,7 @@ const invidiousInstances = youtubeHelper.redirects; const bibliogramInstances = instagramHelper.redirects; const osmInstances = mapsHelper.redirects; const redditInstances = redditHelper.redirects; +const scribeInstances = mediumHelper.redirects; const searchEngineInstances = searchHelper.redirects; const simplyTranslateInstances = googleTranslateHelper.redirects; const wikipediaInstances = wikipediaHelper.redirects; @@ -24,6 +26,7 @@ const autocompletes = [ { id: "bibliogram-instance", instances: bibliogramInstances }, { id: "osm-instance", instances: osmInstances }, { id: "reddit-instance", instances: redditInstances }, + { id: "scribe-instance", instances: scribeInstances }, { id: "search-engine-instance", instances: searchEngineInstances.map((instance) => instance.link), @@ -38,6 +41,7 @@ let invidiousInstance = document.getElementById("invidious-instance"); let bibliogramInstance = document.getElementById("bibliogram-instance"); let osmInstance = document.getElementById("osm-instance"); let redditInstance = document.getElementById("reddit-instance"); +let scribeInstance = document.getElementById("scribe-instance"); let searchEngineInstance = document.getElementById("search-engine-instance"); let simplyTranslateInstance = document.getElementById( "simply-translate-instance" @@ -48,6 +52,7 @@ let disableInvidious = document.getElementById("disable-invidious"); let disableBibliogram = document.getElementById("disable-bibliogram"); let disableOsm = document.getElementById("disable-osm"); let disableReddit = document.getElementById("disable-reddit"); +let disableScribe = document.getElementById("disable-scribe"); let disableSearchEngine = document.getElementById("disable-search-engine"); let disableSimplyTranslate = document.getElementById( "disable-simply-translate" @@ -103,6 +108,7 @@ browser.storage.sync.get( "bibliogramInstance", "osmInstance", "redditInstance", + "scribeInstance", "searchEngineInstance", "simplyTranslateInstance", "wikipediaInstance", @@ -111,6 +117,7 @@ browser.storage.sync.get( "disableBibliogram", "disableOsm", "disableReddit", + "disableScribe", "disableSearchEngine", "disableSimplyTranslate", "disableWikipedia", @@ -139,6 +146,7 @@ browser.storage.sync.get( bibliogramInstance.value = result.bibliogramInstance || ""; osmInstance.value = result.osmInstance || ""; redditInstance.value = result.redditInstance || ""; + scribeInstance.value = result.scribeInstance || ""; searchEngineInstance.value = (result.searchEngineInstance && result.searchEngineInstance.link) || ""; simplyTranslateInstance.value = result.simplyTranslateInstance || ""; @@ -148,6 +156,7 @@ browser.storage.sync.get( disableBibliogram.checked = !result.disableBibliogram; disableOsm.checked = !result.disableOsm; disableReddit.checked = !result.disableReddit; + disableScribe.checked = !result.disableScribe; disableSearchEngine.checked = !result.disableSearchEngine; disableSimplyTranslate.checked = !result.disableSimplyTranslate; disableWikipedia.checked = !result.disableWikipedia; @@ -311,6 +320,15 @@ const redditInstanceChange = debounce(() => { }, 500); redditInstance.addEventListener("input", redditInstanceChange); +const scribeInstanceChange = debounce(() => { + if (scribeInstance.checkValidity()) { + browser.storage.sync.set({ + scribeInstance: parseURL(scribeInstance.value), + }); + } +}, 500); +scribeInstance.addEventListener("input", scribeInstanceChange); + const searchEngineInstanceChange = debounce(() => { const instance = searchEngineInstances.find( (instance) => instance.link === searchEngineInstance.value @@ -369,6 +387,10 @@ disableReddit.addEventListener("change", (event) => { browser.storage.sync.set({ disableReddit: !event.target.checked }); }); +disableScribe.addEventListener("change", (event) => { + browser.storage.sync.set({ disableScribe: !event.target.checked }); +}); + disableSearchEngine.addEventListener("change", (event) => { browser.storage.sync.set({ disableSearchEngine: !event.target.checked }); }); -- cgit 1.4.1 From 362bef86586f04f615b97fdb740424e6568002e0 Mon Sep 17 00:00:00 2001 From: Ngô Ngọc Đức Huy Date: Tue, 12 Oct 2021 15:24:16 +0700 Subject: Fix copy-and-replace mistakes - Change scribe's default input to 'Random instance (none selected)' - Add random pool variables and functions for scribe --- src/pages/background/background.js | 71 ++++++++++++++++++-------------------- src/pages/options/options.html | 2 +- src/pages/options/options.js | 13 ++++++- 3 files changed, 46 insertions(+), 40 deletions(-) (limited to 'src/pages/options') diff --git a/src/pages/background/background.js b/src/pages/background/background.js index 453788c8..d7e37591 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -72,6 +72,7 @@ let useFreeTube; let nitterRandomPool; let invidiousRandomPool; let bibliogramRandomPool; +let scribeRandomPool; let exceptions; window.browser = window.browser || window.chrome; @@ -108,6 +109,7 @@ browser.storage.sync.get( "nitterRandomPool", "invidiousRandomPool", "bibliogramRandomPool", + "scribeRandomPool", "exceptions", ], (result) => { @@ -152,6 +154,9 @@ browser.storage.sync.get( bibliogramRandomPool = result.bibliogramRandomPool ? result.bibliogramRandomPool.split(",") : commonHelper.filterInstances(bibliogramInstances); + scribeRandomPool = result.scribeRandomPool + ? result.scribeRandomPool.split(",") + : commonHelper.filterInstances(bibliogramInstances); } ); @@ -244,6 +249,9 @@ browser.storage.onChanged.addListener((changes) => { if ("bibliogramRandomPool" in changes) { bibliogramRandomPool = changes.bibliogramRandomPool.newValue.split(","); } + if ("scribeRandomPool" in changes) { + scribeRandomPool = changes.scribeRandomPool.newValue.split(","); + } if ("exceptions" in changes) { exceptions = changes.exceptions.newValue.map((e) => { return new RegExp(e); @@ -527,51 +535,38 @@ function redirectReddit(url, initiator, type) { return `${redditInstance}${url.pathname}${url.search}`; } -function redirectScribe(url, initiator, type) { +function redirectMedium(url, initiator) { if (disableScribe || isException(url, initiator)) { return null; } - // Do not redirect when already on the selected view - if ( - (initiator && initiator.origin === scribeInstance) || - url.origin === scribeInstance - ) { + if (url.pathname.split("/").includes("home")) { return null; } - // Do not redirect exclusions nor anything other than main_frame - if (type !== "main_frame") { + if ( + isFirefox() && + initiator && + (initiator.origin === scribeInstance || + scribeInstances.includes(initiator.origin) || + mediumDomains.includes(initiator.host)) + ) { + browser.storage.sync.set({ + redirectBypassFlag: true, + }); return null; } - if (url.host === "i.redd.it") { - if (scribeInstance.includes("libredd")) { - return `${scribeInstance}/img${url.pathname}${url.search}`; - } else if (scribeInstance.includes("teddit")) { - // As of 2021-04-09, redirects for teddit images are nontrivial: - // - navigating to the image before ever navigating to its page causes - // 404 error (probably needs fix on teddit project) - // - some image links on teddit are very different - // Therefore, don't support redirecting image links for teddit. - return null; - } else { - return null; - } - } else if (url.host === "redd.it") { - if ( - scribeInstance.includes("teddit") && - !url.pathname.match(/^\/+[^\/]+\/+[^\/]/) - ) { - // As of 2021-04-22, redirects for teddit redd.it/foo links don't work. - // It appears that adding "/comments" as a prefix works, so manually add - // that prefix if it is missing. Even though redd.it/comments/foo links - // don't seem to work or exist, guard against affecting those kinds of - // paths. - // - // Note the difference between redd.it/comments/foo (doesn't work) and - // teddit.net/comments/foo (works). - return `${scribeInstance}/comments${url.pathname}${url.search}`; - } + if (url.host.split(".")[0] === "pbs" || url.host.split(".")[0] === "video") { + return `${ + scribeInstance || commonHelper.getRandomInstance(scribeRandomPool) + }/pic/${encodeURIComponent(url.href)}`; + } else if (url.pathname.split("/").includes("tweets")) { + return `${ + scribeInstance || commonHelper.getRandomInstance(scribeRandomPool) + }${url.pathname.replace("/tweets", "")}${url.search}`; + } else { + return `${ + scribeInstance || commonHelper.getRandomInstance(scribeRandomPool) + }${url.pathname}${url.search}`; } - return `${scribeInstance}${url.pathname}${url.search}`; } function redirectSearchEngine(url, initiator) { @@ -668,7 +663,7 @@ browser.webRequest.onBeforeRequest.addListener( }; } else if (mediumDomains.includes(url.host)) { redirect = { - redirectUrl: redirectScribe(url, initiator, details.type), + redirectUrl: redirectMedium(url, initiator, details.type), }; } else if (url.href.match(googleSearchRegex)) { redirect = { diff --git a/src/pages/options/options.html b/src/pages/options/options.html index 43db929d..bafff5f8 100644 --- a/src/pages/options/options.html +++ b/src/pages/options/options.html @@ -284,7 +284,7 @@
diff --git a/src/pages/options/options.js b/src/pages/options/options.js index 938abd24..71bdc99e 100644 --- a/src/pages/options/options.js +++ b/src/pages/options/options.js @@ -73,6 +73,7 @@ let useFreeTube = document.getElementById("use-freetube"); let nitterRandomPool = document.getElementById("nitter-random-pool"); let invidiousRandomPool = document.getElementById("invidious-random-pool"); let bibliogramRandomPool = document.getElementById("bibliogram-random-pool"); +let scribeRandomPool = document.getElementById("scribe-random-pool"); let exceptions; window.browser = window.browser || window.chrome; @@ -137,6 +138,7 @@ browser.storage.sync.get( "nitterRandomPool", "invidiousRandomPool", "bibliogramRandomPool", + "scribeRandomPool", ], (result) => { theme.value = result.theme || ""; @@ -184,6 +186,9 @@ browser.storage.sync.get( bibliogramRandomPool.value = result.bibliogramRandomPool || commonHelper.filterInstances(bibliogramInstances); + scribeRandomPool.value = + result.scribeRandomPool || + commonHelper.filterInstances(scribeInstances); } ); @@ -474,7 +479,13 @@ const bibliogramRandomPoolChange = debounce(() => { bibliogramRandomPool: bibliogramRandomPool.value, }); }, 500); -bibliogramRandomPool.addEventListener("input", bibliogramRandomPoolChange); + +const scribeRandomPoolChange = debounce(() => { + browser.storage.sync.set({ + scribeRandomPool: scribeRandomPool.value, + }); +}, 500); +scribeRandomPool.addEventListener("input", scribeRandomPoolChange); theme.addEventListener("change", (event) => { const value = event.target.options[theme.selectedIndex].value; -- cgit 1.4.1 From 9acdf590994fb93fe7a24a10244348769a360907 Mon Sep 17 00:00:00 2001 From: Ngô Ngọc Đức Huy Date: Wed, 13 Oct 2021 15:59:42 +0700 Subject: Restore the mistakenly removed line Bibliogram randomization would be removed if that removal were merged. --- src/pages/options/options.js | 1 + 1 file changed, 1 insertion(+) (limited to 'src/pages/options') diff --git a/src/pages/options/options.js b/src/pages/options/options.js index 71bdc99e..4a148dfd 100644 --- a/src/pages/options/options.js +++ b/src/pages/options/options.js @@ -479,6 +479,7 @@ const bibliogramRandomPoolChange = debounce(() => { bibliogramRandomPool: bibliogramRandomPool.value, }); }, 500); +bibliogramRandomPool.addEventListener("input", bibliogramRandomPoolChange); const scribeRandomPoolChange = debounce(() => { browser.storage.sync.set({ -- cgit 1.4.1 From e9f957f7d55a940aaa4600dc1d3209bb53e71a39 Mon Sep 17 00:00:00 2001 From: Ngô Ngọc Đức Huy Date: Sun, 17 Oct 2021 19:30:51 +0700 Subject: Add "New" badge for Scribe --- src/pages/options/options.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/pages/options') diff --git a/src/pages/options/options.html b/src/pages/options/options.html index bafff5f8..7ae481c2 100644 --- a/src/pages/options/options.html +++ b/src/pages/options/options.html @@ -210,7 +210,7 @@
-

Wikipedia Redirects

+

Wikipedia Redirects

-

Scribe Instance

+

Scribe Instance

Date: Sun, 17 Oct 2021 20:03:02 +0700 Subject: Add data attributes for scribe random pool This fixes random pool dropdown brokeness --- src/pages/options/options.html | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) (limited to 'src/pages/options') diff --git a/src/pages/options/options.html b/src/pages/options/options.html index 7ae481c2..5b68ed10 100644 --- a/src/pages/options/options.html +++ b/src/pages/options/options.html @@ -279,11 +279,14 @@
-

Scribe Instance

+

Scribe Instance

@@ -589,6 +592,16 @@ type="text" />
+
+

+ Scribe random instance pool (comma-separated) +

+ +

-- cgit 1.4.1