diff --git a/src/assets/javascripts/helpers/instagram.js b/src/assets/javascripts/helpers/instagram.js index fc004e0..3145fb6 100644 --- a/src/assets/javascripts/helpers/instagram.js +++ b/src/assets/javascripts/helpers/instagram.js @@ -101,7 +101,7 @@ function setDisable(val) { } let protocol; -const getprotocol = () => protocol; +const getProtocol = () => protocol; function setProtocol(val) { protocol = val; browser.storage.local.set({ nitterProtocol: val }) @@ -182,7 +182,7 @@ export default { getDisable, setDisable, - getprotocol, + getProtocol, setProtocol, getBibliogramNormalRedirectsChecks, diff --git a/src/assets/javascripts/helpers/medium.js b/src/assets/javascripts/helpers/medium.js index dcec574..cd45917 100644 --- a/src/assets/javascripts/helpers/medium.js +++ b/src/assets/javascripts/helpers/medium.js @@ -20,19 +20,16 @@ const targets = [ let redirects = { "scribe": { - "normal": [ - "https://scribe.rip", - "https://scribe.nixnet.services", - "https://scribe.citizen4.eu", - "https://scribe.bus-hit.me" - ] + "normal": [], + "tor": [] } }; const getRedirects = () => redirects; const getCustomRedirects = function () { return { "scribe": { - "normal": [...scribeNormalRedirectsChecks, ...scribeNormalCustomRedirects] + "normal": [...scribeNormalRedirectsChecks, ...scribeNormalCustomRedirects], + "tor": [...scribeTorRedirectsChecks, ...scribeTorCustomRedirects] }, }; }; @@ -45,6 +42,18 @@ function setRedirects(val) { if (index !== -1) scribeNormalRedirectsChecks.splice(index, 1); } setScribeNormalRedirectsChecks(scribeNormalRedirectsChecks); + + for (const item of scribeNormalRedirectsChecks) if (!redirects.scribe.normal.includes(item)) { + var index = scribeNormalRedirectsChecks.indexOf(item); + if (index !== -1) scribeNormalRedirectsChecks.splice(index, 1); + } + setScribeNormalRedirectsChecks(scribeNormalRedirectsChecks); + + for (const item of scribeTorRedirectsChecks) if (!redirects.scribe.normal.includes(item)) { + var index = scribeTorRedirectsChecks.indexOf(item); + if (index !== -1) scribeTorRedirectsChecks.splice(index, 1); + } + setScribeTorRedirectsChecks(scribeTorRedirectsChecks); } let scribeNormalRedirectsChecks; @@ -55,6 +64,14 @@ function setScribeNormalRedirectsChecks(val) { console.log("scribeNormalRedirectsChecks: ", val) } +let scribeTorRedirectsChecks; +const getScribeTorRedirectsChecks = () => scribeTorRedirectsChecks; +function setScribeTorRedirectsChecks(val) { + scribeTorRedirectsChecks = val; + browser.storage.local.set({ scribeTorRedirectsChecks }) + console.log("scribeTorRedirectsChecks: ", val) +} + let scribeNormalCustomRedirects = []; const getScribeNormalCustomRedirects = () => scribeNormalCustomRedirects; function setScribeNormalCustomRedirects(val) { @@ -63,6 +80,14 @@ function setScribeNormalCustomRedirects(val) { console.log("scribeNormalCustomRedirects: ", val) } +let scribeTorCustomRedirects = []; +const getScribeTorCustomRedirects = () => scribeTorCustomRedirects; +function setScribeTorCustomRedirects(val) { + scribeTorCustomRedirects = val; + browser.storage.local.set({ scribeTorCustomRedirects }) + console.log("scribeTorCustomRedirects: ", val) +} + let disable; const getDisable = () => disable; function setDisable(val) { @@ -71,6 +96,14 @@ function setDisable(val) { console.log("disableMedium", disable) } +let protocol; +const getProtocol = () => protocol; +function setProtocol(val) { + protocol = val; + browser.storage.local.set({ mediumProtocol: val }) + console.log("mediumProtocol: ", val) +} + function isMedium(url, initiator) { if (disable) return false; if (url.pathname == "/") return false; @@ -86,7 +119,9 @@ function redirect(url, type) { if (type != "main_frame" && "sub_frame" && "xmlhttprequest" && "other") return null; - let instancesList = [...scribeNormalRedirectsChecks, ...scribeNormalCustomRedirects]; + let instancesList; + if (protocol == 'normal') instancesList = [...scribeNormalRedirectsChecks, ...scribeNormalCustomRedirects]; + else if (protocol == 'tor') instancesList = [...scribeTorRedirectsChecks, ...scribeTorCustomRedirects]; if (instancesList.length === 0) return null; let randomInstance = commonHelper.getRandomInstance(instancesList) @@ -95,26 +130,37 @@ function redirect(url, type) { async function init() { return new Promise((resolve) => { - browser.storage.local.get( - [ - "disableMedium", - "mediumRedirects", - "scribeNormalRedirectsChecks", - "scribeNormalCustomRedirects", - ], - (result) => { - disable = result.disableMedium ?? false; + fetch('/instances/data.json').then(response => response.text()).then(data => { + let dataJson = JSON.parse(data); + browser.storage.local.get( + [ + "disableMedium", + "mediumRedirects", + "scribeNormalRedirectsChecks", + "scribeNormalCustomRedirects", + "scribeTorRedirectsChecks", + "scribeTorCustomRedirects", + "mediumProtocol" + ], + (result) => { + disable = result.disableMedium ?? false; - if (result.mediumRedirects) redirects = result.mediumRedirects; + protocol = result.mediumProtocol ?? "normal"; - scribeNormalRedirectsChecks = result.scribeNormalRedirectsChecks ?? [...redirects.scribe.normal]; - scribeNormalCustomRedirects = result.scribeNormalCustomRedirects ?? []; + redirects.scribe = dataJson.scribe; + if (result.mediumRedirects) redirects = result.mediumRedirects; - resolve(); - } - ) + scribeNormalRedirectsChecks = result.scribeNormalRedirectsChecks ?? [...redirects.scribe.normal]; + scribeNormalCustomRedirects = result.scribeNormalCustomRedirects ?? []; + + scribeTorRedirectsChecks = result.scribeTorRedirectsChecks ?? [...redirects.scribe.tor]; + scribeTorCustomRedirects = result.scribeTorCustomRedirects ?? []; + + resolve(); + } + ) + }) }) - } export default { @@ -127,11 +173,18 @@ export default { getDisable, setDisable, + getProtocol, + setProtocol, + getScribeNormalRedirectsChecks, setScribeNormalRedirectsChecks, + getScribeTorRedirectsChecks, + setScribeTorRedirectsChecks, getScribeNormalCustomRedirects, setScribeNormalCustomRedirects, + getScribeTorCustomRedirects, + setScribeTorCustomRedirects, redirect, isMedium, diff --git a/src/assets/javascripts/helpers/reddit.js b/src/assets/javascripts/helpers/reddit.js index 08b3e52..382f15c 100644 --- a/src/assets/javascripts/helpers/reddit.js +++ b/src/assets/javascripts/helpers/reddit.js @@ -177,7 +177,7 @@ function setRedditFrontend(val) { }; let protocol; -const getprotocol = () => protocol; +const getProtocol = () => protocol; function setProtocol(val) { protocol = val; browser.storage.local.set({ redditProtocol: val }) @@ -316,7 +316,7 @@ export default { getRedditFrontend, setRedditFrontend, - getprotocol, + getProtocol, setProtocol, getLibredditNormalRedirectsChecks, diff --git a/src/assets/javascripts/helpers/search.js b/src/assets/javascripts/helpers/search.js index caa0399..789f7d9 100644 --- a/src/assets/javascripts/helpers/search.js +++ b/src/assets/javascripts/helpers/search.js @@ -146,7 +146,7 @@ function setFrontend(val) { }; let protocol; -const getprotocol = () => protocol; +const getProtocol = () => protocol; function setProtocol(val) { protocol = val; browser.storage.local.set({ searchProtocol: val }) @@ -274,7 +274,7 @@ export default { getSearxTorCustomRedirects, setSearxTorCustomRedirects, - getprotocol, + getProtocol, setProtocol, redirect, diff --git a/src/assets/javascripts/helpers/twitter.js b/src/assets/javascripts/helpers/twitter.js index 3edea7a..a1b9979 100644 --- a/src/assets/javascripts/helpers/twitter.js +++ b/src/assets/javascripts/helpers/twitter.js @@ -88,7 +88,7 @@ function setDisable(val) { } let protocol; -const getprotocol = () => protocol; +const getProtocol = () => protocol; function setProtocol(val) { protocol = val; browser.storage.local.set({ nitterProtocol: val }) @@ -187,7 +187,7 @@ export default { getNitterTorCustomRedirects, setNitterTorCustomRedirects, - getprotocol, + getProtocol, setProtocol, redirect, diff --git a/src/assets/javascripts/helpers/wikipedia.js b/src/assets/javascripts/helpers/wikipedia.js index e27f80b..0211063 100644 --- a/src/assets/javascripts/helpers/wikipedia.js +++ b/src/assets/javascripts/helpers/wikipedia.js @@ -146,12 +146,12 @@ async function init() { "wikilessTorRedirectsChecks", "wikilessNormalCustomRedirects", "wikilessTorCustomRedirects", - "wikilessProtocol" + "wikipediaProtocol" ], (result) => { disable = result.disableWikipedia ?? false; - protocol = result.wikilessProtocol ?? "normal"; + protocol = result.wikipediaProtocol ?? "normal"; redirects.wikiless = dataJson.wikiless; if (result.wikipediaRedirects) redirects = result.wikipediaRedirects; diff --git a/src/assets/javascripts/helpers/youtube/youtube.js b/src/assets/javascripts/helpers/youtube/youtube.js index 70148f7..2feb64a 100644 --- a/src/assets/javascripts/helpers/youtube/youtube.js +++ b/src/assets/javascripts/helpers/youtube/youtube.js @@ -136,7 +136,7 @@ function setDisable(val) { let protocol; -const getprotocol = () => protocol; +const getProtocol = () => protocol; function setProtocol(val) { protocol = val; browser.storage.local.set({ youtubeProtocol: val }) @@ -573,7 +573,7 @@ export default { getDisable, setDisable, - getprotocol, + getProtocol, setProtocol, setInvidiousAlwaysProxy, diff --git a/src/instances/data.json b/src/instances/data.json index fe7c400..80f6d43 100644 --- a/src/instances/data.json +++ b/src/instances/data.json @@ -74,7 +74,8 @@ "https://de.nttr.stream", "https://nitter.winscloud.net", "https://nitter.tiekoetter.com", - "https://nitter.spaceint.fr" + "https://nitter.spaceint.fr", + "https://twtr.bch.bar" ], "tor": [ "http://3nzoldnxplag42gqjs23xvghtzf6t6yzssrtytnntc6ppc7xxuoneoad.onion", @@ -156,7 +157,8 @@ "https://scribe.nixnet.services", "https://scribe.citizen4.eu", "https://scribe.bus-hit.me" - ] + ], + "tor": [] }, "simplyTranslate": { "normal": [ diff --git a/src/instances/get_instances.py b/src/instances/get_instances.py index 3aee6cd..8f95af1 100644 --- a/src/instances/get_instances.py +++ b/src/instances/get_instances.py @@ -106,6 +106,7 @@ r = requests.get( rJson = json.loads(r.text) scribeList = {} scribeList['normal'] = [] +scribeList['tor'] = [] for item in rJson: scribeList['normal'].append(item) mightyList['scribe'] = scribeList diff --git a/src/pages/options/instagram/instagram.js b/src/pages/options/instagram/instagram.js index c5ed805..9967176 100644 --- a/src/pages/options/instagram/instagram.js +++ b/src/pages/options/instagram/instagram.js @@ -31,7 +31,7 @@ function changeProtocolSettings(protocol) { instagramHelper.init().then(() => { disableInstagramElement.checked = !instagramHelper.getDisable(); - let protocol = instagramHelper.getprotocol(); + let protocol = instagramHelper.getProtocol(); protocolElement.value = protocol; changeProtocolSettings(protocol); diff --git a/src/pages/options/medium/medium.html b/src/pages/options/medium/medium.html index 9efd21c..f19f8d4 100644 --- a/src/pages/options/medium/medium.html +++ b/src/pages/options/medium/medium.html @@ -2,146 +2,179 @@ - - - - - - LibRedirect Options: Medium + + + + + + LibRedirect Options: Medium - + d="M19,5v14H5V5H19 M19,3H5C3.9,3,3,3.9,3,5v14c0,1.1,0.9,2,2,2h14c1.1,0,2-0.9,2-2V5C21,3.9,20.1,3,19,3L19,3z" /> + + + + + Medium + + -
+
+
+

Enable

+ +
+ + +
+

Protocol

+ +
+ +
+ +
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
-

Enable

- + +
+
+
+
-
- +
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
-

Default Instances

+ +
-
-
-
-

Custom Instances

-
- -
- - -
-
-
-
+ +
+ +
- - - + + + - + \ No newline at end of file diff --git a/src/pages/options/medium/medium.js b/src/pages/options/medium/medium.js index 8c302fc..dcc4b4a 100644 --- a/src/pages/options/medium/medium.js +++ b/src/pages/options/medium/medium.js @@ -6,9 +6,36 @@ disableMediumElement.addEventListener("change", (event) => mediumHelper.setDisable(!event.target.checked) ); +let protocolElement = document.getElementById("protocol") +protocolElement.addEventListener("change", + (event) => { + let protocol = event.target.options[protocolElement.selectedIndex].value + mediumHelper.setProtocol(protocol); + changeProtocolSettings(protocol); + } +); + +function changeProtocolSettings(protocol) { + let normalDiv = document.getElementById("normal"); + let torDiv = document.getElementById("tor"); + if (protocol == 'normal') { + normalDiv.style.display = 'block'; + torDiv.style.display = 'none'; + } + else if (protocol == 'tor') { + normalDiv.style.display = 'none'; + torDiv.style.display = 'block'; + } +} + + mediumHelper.init().then(() => { disableMediumElement.checked = !mediumHelper.getDisable(); + let protocol = mediumHelper.getProtocol(); + protocolElement.value = protocol; + changeProtocolSettings(protocol); + commonHelper.processDefaultCustomInstances( 'scribe', 'normal', @@ -19,4 +46,15 @@ mediumHelper.init().then(() => { mediumHelper.getScribeNormalCustomRedirects, mediumHelper.setScribeNormalCustomRedirects ) + + commonHelper.processDefaultCustomInstances( + 'scribe', + 'tor', + mediumHelper, + document, + mediumHelper.getScribeTorRedirectsChecks, + mediumHelper.setScribeTorRedirectsChecks, + mediumHelper.getScribeTorCustomRedirects, + mediumHelper.setScribeTorCustomRedirects + ) }) \ No newline at end of file diff --git a/src/pages/options/reddit/reddit.js b/src/pages/options/reddit/reddit.js index c682c3f..57702dc 100644 --- a/src/pages/options/reddit/reddit.js +++ b/src/pages/options/reddit/reddit.js @@ -65,7 +65,7 @@ redditHelper.init().then(() => { redditFrontendElement.value = frontend; changeFrontendsSettings(frontend); - let protocol = redditHelper.getprotocol(); + let protocol = redditHelper.getProtocol(); protocolElement.value = protocol; changeProtocolSettings(protocol); diff --git a/src/pages/options/search/search.js b/src/pages/options/search/search.js index a240c05..e4ce9d6 100644 --- a/src/pages/options/search/search.js +++ b/src/pages/options/search/search.js @@ -65,7 +65,7 @@ searchHelper.init().then(() => { searchFrontendElement.value = frontend; changeFrontendsSettings(frontend); - let protocol = searchHelper.getprotocol(); + let protocol = searchHelper.getProtocol(); protocolElement.value = protocol; changeProtocolSettings(protocol); diff --git a/src/pages/options/twitter/twitter.js b/src/pages/options/twitter/twitter.js index 88fadb7..f76230f 100644 --- a/src/pages/options/twitter/twitter.js +++ b/src/pages/options/twitter/twitter.js @@ -32,7 +32,7 @@ function changeProtocolSettings(protocol) { twitterHelper.init().then(() => { disableTwitterElement.checked = !twitterHelper.getDisable(); - let protocol = twitterHelper.getprotocol(); + let protocol = twitterHelper.getProtocol(); protocolElement.value = protocol; changeProtocolSettings(protocol); diff --git a/src/pages/options/youtube/youtube.js b/src/pages/options/youtube/youtube.js index d62bdad..cee3813 100644 --- a/src/pages/options/youtube/youtube.js +++ b/src/pages/options/youtube/youtube.js @@ -144,7 +144,7 @@ youtubeHelper.init().then(() => { youtubeFrontendElement.value = frontend; changeFrontendsSettings(frontend); - let protocol = youtubeHelper.getprotocol(); + let protocol = youtubeHelper.getProtocol(); protocolElement.value = protocol; changeProtocolSettings(protocol);