diff options
author | ManeraKai <manerakai@protonmail.com> | 2022-02-23 07:19:56 +0300 |
---|---|---|
committer | ManeraKai <manerakai@protonmail.com> | 2022-02-23 07:19:56 +0300 |
commit | 2acbcca30c551284a14b825afe8d67f7fff1e4e0 (patch) | |
tree | f324896a8c726fa44ff76ca64f1e607523800132 /src/assets | |
parent | Added wikipedia tor support #32 (diff) | |
download | libredirect-2acbcca30c551284a14b825afe8d67f7fff1e4e0.zip |
Added medium tor support #32
Diffstat (limited to 'src/assets')
-rw-r--r-- | src/assets/javascripts/helpers/instagram.js | 4 | ||||
-rw-r--r-- | src/assets/javascripts/helpers/medium.js | 107 | ||||
-rw-r--r-- | src/assets/javascripts/helpers/reddit.js | 4 | ||||
-rw-r--r-- | src/assets/javascripts/helpers/search.js | 4 | ||||
-rw-r--r-- | src/assets/javascripts/helpers/twitter.js | 4 | ||||
-rw-r--r-- | src/assets/javascripts/helpers/wikipedia.js | 4 | ||||
-rw-r--r-- | src/assets/javascripts/helpers/youtube/youtube.js | 4 |
7 files changed, 92 insertions, 39 deletions
diff --git a/src/assets/javascripts/helpers/instagram.js b/src/assets/javascripts/helpers/instagram.js index fc004e09..3145fb65 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 dcec5743..cd459177 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; - - if (result.mediumRedirects) redirects = result.mediumRedirects; - - scribeNormalRedirectsChecks = result.scribeNormalRedirectsChecks ?? [...redirects.scribe.normal]; - scribeNormalCustomRedirects = result.scribeNormalCustomRedirects ?? []; - - resolve(); - } - ) + 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; + + protocol = result.mediumProtocol ?? "normal"; + + redirects.scribe = dataJson.scribe; + if (result.mediumRedirects) redirects = result.mediumRedirects; + + 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 08b3e528..382f15cc 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 caa0399f..789f7d97 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 3edea7ac..a1b9979b 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 e27f80bc..02110639 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 70148f7d..2feb64a0 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, |