diff options
author | ManeraKai <manerakai@protonmail.com> | 2022-03-15 14:48:36 +0300 |
---|---|---|
committer | ManeraKai <manerakai@protonmail.com> | 2022-03-15 14:48:36 +0300 |
commit | 1e1ed7bd7f9aaa2d4ce4c68167e1f22adbff4f01 (patch) | |
tree | 9aff107223bc64009c2fea28a395e5d9370f3eb9 /src/assets | |
parent | Added simpleertube #78 (diff) | |
download | libredirect-1e1ed7bd7f9aaa2d4ce4c68167e1f22adbff4f01.zip |
Readded medium custom domin names #94
Diffstat (limited to 'src/assets')
-rw-r--r-- | src/assets/javascripts/helpers/medium.js | 65 |
1 files changed, 35 insertions, 30 deletions
diff --git a/src/assets/javascripts/helpers/medium.js b/src/assets/javascripts/helpers/medium.js index f1425afa..10d56646 100644 --- a/src/assets/javascripts/helpers/medium.js +++ b/src/assets/javascripts/helpers/medium.js @@ -7,15 +7,25 @@ const targets = [ /^medium\.com/, /.*\.medium\.com/, // // Other domains of medium blogs, source(s): https://findingtom.com/best-medium-blogs-to-follow/#1-forge - // /towardsdatascience\.com/, - // /uxdesign\.cc/, - // /uxplanet\.org/, - // /betterprogramming\.pub/, - // /aninjusticemag\.com/, - // /betterhumans\.pub/, - // /psiloveyou\.xyz/, - // /entrepreneurshandbook\.co/, - // /blog\.coinbase\.com/ + + /^towardsdatascience\.com/, + /^uxdesign\.cc/, + /^uxplanet\.org/, + /^betterprogramming\.pub/, + /^aninjusticemag\.com/, + /^betterhumans\.pub/, + /^psiloveyou\.xyz/, + /^entrepreneurshandbook\.co/, + /^blog\.coinbase\.com/, + + /^ levelup\.gitconnected\.com /, + /^javascript\.plainenglish\.io /, + /^blog\.bitsrc\.io /, + /^ itnext\.io /, + /^codeburst\.io /, + /^infosecwriteups\.com /, + /^ blog\.devgenius.io /, + /^ writingcooperative\.com /, ]; let redirects = { @@ -104,21 +114,17 @@ function setProtocol(val) { console.log("mediumProtocol: ", val); } -function isMedium(url, initiator) { - if (disable) return false; - if (url.pathname == "/") return false; - - if ( - commonHelper.isFirefox() && - initiator && ([...redirects.scribe.normal, ...scribeNormalCustomRedirects].includes(initiator.origin) || targets.includes(initiator.host)) - ) return false; +function redirect(url, type, initiator) { - return targets.some((rx) => rx.test(url.host)); -} -function redirect(url, type) { + if (disable) return; + if (url.pathname == "/") return; if (type != "main_frame" && "sub_frame" && "xmlhttprequest" && "other") return null; + if (initiator && ([...redirects.scribe.normal, ...scribeNormalCustomRedirects].includes(initiator.origin))) return; + + if (!targets.some((rx) => rx.test(url.host))) return; + let instancesList; if (protocol == 'normal') instancesList = [...scribeNormalRedirectsChecks, ...scribeNormalCustomRedirects]; else if (protocol == 'tor') instancesList = [...scribeTorRedirectsChecks, ...scribeTorCustomRedirects]; @@ -156,7 +162,7 @@ function changeInstance(url) { } async function init() { - return new Promise((resolve) => { + return new Promise(resolve => { fetch('/instances/data.json').then(response => response.text()).then(data => { let dataJson = JSON.parse(data); browser.storage.local.get( @@ -169,19 +175,19 @@ async function init() { "scribeTorCustomRedirects", "mediumProtocol" ], - (result) => { - disable = result.disableMedium ?? false; + r => { + disable = r.disableMedium ?? true; - protocol = result.mediumProtocol ?? "normal"; + protocol = r.mediumProtocol ?? "normal"; redirects.scribe = dataJson.scribe; - if (result.mediumRedirects) redirects = result.mediumRedirects; + if (r.mediumRedirects) redirects = r.mediumRedirects; - scribeNormalRedirectsChecks = result.scribeNormalRedirectsChecks ?? [...redirects.scribe.normal]; - scribeNormalCustomRedirects = result.scribeNormalCustomRedirects ?? []; + scribeNormalRedirectsChecks = r.scribeNormalRedirectsChecks ?? [...redirects.scribe.normal]; + scribeNormalCustomRedirects = r.scribeNormalCustomRedirects ?? []; - scribeTorRedirectsChecks = result.scribeTorRedirectsChecks ?? [...redirects.scribe.tor]; - scribeTorCustomRedirects = result.scribeTorCustomRedirects ?? []; + scribeTorRedirectsChecks = r.scribeTorRedirectsChecks ?? [...redirects.scribe.tor]; + scribeTorCustomRedirects = r.scribeTorCustomRedirects ?? []; resolve(); } @@ -214,7 +220,6 @@ export default { setScribeTorCustomRedirects, redirect, - isMedium, init, changeInstance, }; |