From 468f9ff12cb88cf67ce14aa533f8c1c709923ff7 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Fri, 22 Jul 2022 05:19:21 +0000 Subject: Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 2c80a614..dc24c751 100644 --- a/README.md +++ b/README.md @@ -2,9 +2,9 @@ A web extension that redirects YouTube, Twitter, Instagram... requests to alternative privacy friendly frontends and backends. -[![Matrix Badge](https://img.shields.io/matrix/libredirect:matrix.org?label=matrix%20chat)](https://matrix.to/#/#libredirect:tokhmi.xyz) +[![Matrix Badge](https://img.shields.io/matrix/libredirect:matrix.org?label=matrix%20chat)](https://matrix.to/#/#libredirect-space:matrix.org) [![Firefox users Badge](https://img.shields.io/amo/users/libredirect?label=Firefox%20users)](https://addons.mozilla.org/firefox/addon/libredirect/) -[![Matrix Badge](https://img.shields.io/liberapay/gives/libredirect?label=Liberapay)](https://liberapay.com/LibRedirect) +[![LibrePay Badge](https://img.shields.io/liberapay/gives/libredirect?label=Liberapay)](https://liberapay.com/LibRedirect) [![Firefox Add-on](./img/badge-amo.png)](https://addons.mozilla.org/firefox/addon/libredirect/)  -- cgit 1.4.1 From 46d75b4d8c59fa98f62cfc12ca14fd314f0b6ba6 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Sun, 24 Jul 2022 09:44:39 +0000 Subject: Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index 6e424d12..acfe7010 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A web extension that redirects YouTube, Twitter, Instagram... requests to alternative privacy friendly frontends and backends. -[![Matrix Badge](https://img.shields.io/matrix/libredirect:matrix.org?label=matrix%20chat)](https://matrix.to/#/#libredirect-space:matrix.org) +[![Matrix Badge](https://img.shields.io/matrix/libredirect-space:matrix.org?label=matrix%20chat)](https://matrix.to/#/#libredirect-space:matrix.org) [![Firefox users Badge](https://img.shields.io/amo/users/libredirect?label=Firefox%20users)](https://addons.mozilla.org/firefox/addon/libredirect/) [![LibrePay Badge](https://img.shields.io/liberapay/gives/libredirect?label=Liberapay)](https://liberapay.com/LibRedirect) -- cgit 1.4.1 From b2a24fbb9962b5ed5c13cd1ce34d2aa9c2ad0346 Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Sun, 24 Jul 2022 09:46:29 +0000 Subject: Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index acfe7010..6e424d12 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A web extension that redirects YouTube, Twitter, Instagram... requests to alternative privacy friendly frontends and backends. -[![Matrix Badge](https://img.shields.io/matrix/libredirect-space:matrix.org?label=matrix%20chat)](https://matrix.to/#/#libredirect-space:matrix.org) +[![Matrix Badge](https://img.shields.io/matrix/libredirect:matrix.org?label=matrix%20chat)](https://matrix.to/#/#libredirect-space:matrix.org) [![Firefox users Badge](https://img.shields.io/amo/users/libredirect?label=Firefox%20users)](https://addons.mozilla.org/firefox/addon/libredirect/) [![LibrePay Badge](https://img.shields.io/liberapay/gives/libredirect?label=Liberapay)](https://liberapay.com/LibRedirect) -- cgit 1.4.1 From 7a32d78398a343f5dfac51b6f53c333c16ae784a Mon Sep 17 00:00:00 2001 From: BobIsMyManager Date: Wed, 27 Jul 2022 11:40:01 +0100 Subject: Add new frontends to readme --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index de3788b6..cc2fcc89 100644 --- a/README.md +++ b/README.md @@ -19,8 +19,8 @@ A web extension that redirects YouTube, Twitter, Instagram... requests to altern     -Youtube => [Invidious](https://github.com/iv-org/invidious), [Piped](https://github.com/TeamPiped/Piped), [Piped-Material](https://github.com/mmjee/Piped-Material), [FreeTube](https://github.com/FreeTubeApp/FreeTube), [Yattee](https://github.com/yattee/yattee)\ -Youtube Music => [Beatbump](https://github.com/snuffyDev/Beatbump)\ +Youtube => [Invidious](https://github.com/iv-org/invidious), [Piped](https://github.com/TeamPiped/Piped), [Piped-Material](https://github.com/mmjee/Piped-Material), [CloudTube](https://sr.ht/~cadence/tube/) [FreeTube](https://github.com/FreeTubeApp/FreeTube), [Yattee](https://github.com/yattee/yattee)\ +Youtube Music => [Beatbump](https://github.com/snuffyDev/Beatbump), [Hyperpipe](https://codeberg.org/Hyperpipe/Hyperpipe)\ Twitter => [Nitter](https://github.com/zedeus/nitter)\ Instagram => [Bibliogram](https://sr.ht/~cadence/bibliogram/)\ TikTok => [ProxiTok](https://github.com/pablouser1/ProxiTok)\ @@ -31,7 +31,7 @@ Medium => [Scribe](https://sr.ht/~edwardloveall/scribe/)\ Quora => [Quetre](https://github.com/zyachel/quetre)\ IMDb => [Libremdb](https://github.com/zyachel/libremdb)\ PeerTube => [SimpleerTube](https://git.sr.ht/~metalune/simpleweb_peertube)\ -LBRY/Odysee => [Librarian](https://codeberg.org/librarian/librarian)\ +LBRY/Odysee => [Librarian](https://codeberg.org/librarian/librarian) [LBRY Desktop](https://lbry.com/get)\ Search => [SearXNG](https://github.com/searxng/searxng), [SearX](https://searx.github.io/searx/), [Whoogle](https://benbusby.com/projects/whoogle-search/), [Librex](https://github.com/hnhx/librex/)\ Translate => [SimplyTranslate](https://git.sr.ht/~metalune/simplytranslate_web), [LingvaTranslate](https://github.com/TheDavidDelta/lingva-translate)\ Maps => [OpenStreetMap](https://www.openstreetmap.org/), [FacilMap](https://github.com/FacilMap/facilmap)\ -- cgit 1.4.1 From ab1e22459ea382c21077234db1529e8371299860 Mon Sep 17 00:00:00 2001 From: BobIsMyManager Date: Wed, 27 Jul 2022 11:40:44 +0100 Subject: , --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index cc2fcc89..10539b3d 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ Medium => [Scribe](https://sr.ht/~edwardloveall/scribe/)\ Quora => [Quetre](https://github.com/zyachel/quetre)\ IMDb => [Libremdb](https://github.com/zyachel/libremdb)\ PeerTube => [SimpleerTube](https://git.sr.ht/~metalune/simpleweb_peertube)\ -LBRY/Odysee => [Librarian](https://codeberg.org/librarian/librarian) [LBRY Desktop](https://lbry.com/get)\ +LBRY/Odysee => [Librarian](https://codeberg.org/librarian/librarian), [LBRY Desktop](https://lbry.com/get)\ Search => [SearXNG](https://github.com/searxng/searxng), [SearX](https://searx.github.io/searx/), [Whoogle](https://benbusby.com/projects/whoogle-search/), [Librex](https://github.com/hnhx/librex/)\ Translate => [SimplyTranslate](https://git.sr.ht/~metalune/simplytranslate_web), [LingvaTranslate](https://github.com/TheDavidDelta/lingva-translate)\ Maps => [OpenStreetMap](https://www.openstreetmap.org/), [FacilMap](https://github.com/FacilMap/facilmap)\ -- cgit 1.4.1 From d71c2b1e6f95633eb36a6d27012bd92d48ed21ee Mon Sep 17 00:00:00 2001 From: BobIsMyManager Date: Wed, 27 Jul 2022 12:43:08 +0100 Subject: , --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index 10539b3d..611ee14e 100644 --- a/README.md +++ b/README.md @@ -19,7 +19,7 @@ A web extension that redirects YouTube, Twitter, Instagram... requests to altern     -Youtube => [Invidious](https://github.com/iv-org/invidious), [Piped](https://github.com/TeamPiped/Piped), [Piped-Material](https://github.com/mmjee/Piped-Material), [CloudTube](https://sr.ht/~cadence/tube/) [FreeTube](https://github.com/FreeTubeApp/FreeTube), [Yattee](https://github.com/yattee/yattee)\ +Youtube => [Invidious](https://github.com/iv-org/invidious), [Piped](https://github.com/TeamPiped/Piped), [Piped-Material](https://github.com/mmjee/Piped-Material), [CloudTube](https://sr.ht/~cadence/tube/), [FreeTube](https://github.com/FreeTubeApp/FreeTube), [Yattee](https://github.com/yattee/yattee)\ Youtube Music => [Beatbump](https://github.com/snuffyDev/Beatbump), [Hyperpipe](https://codeberg.org/Hyperpipe/Hyperpipe)\ Twitter => [Nitter](https://github.com/zedeus/nitter)\ Instagram => [Bibliogram](https://sr.ht/~cadence/bibliogram/)\ -- cgit 1.4.1 From 9a884ca5c0a5217543dbce6b20ff457fcd5fbaa0 Mon Sep 17 00:00:00 2001 From: BobIsMyManager Date: Mon, 1 Aug 2022 14:28:15 +0100 Subject: http status --- README.md | 2 +- package.json | 5 +++-- src/assets/javascripts/utils.js | 11 +++++++---- src/instances/get_instances.py | 19 ++++++++++++++++++- src/pages/options/widgets/general.js | 11 +++++++++++ src/pages/widgets/links.pug | 6 +++--- 6 files changed, 43 insertions(+), 11 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 3bbf2b3e..a9e68391 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ Quora => [Quetre](https://github.com/zyachel/quetre)\ IMDb => [Libremdb](https://github.com/zyachel/libremdb)\ PeerTube => [SimpleerTube](https://git.sr.ht/~metalune/simpleweb_peertube)\ LBRY/Odysee => [Librarian](https://codeberg.org/librarian/librarian), [LBRY Desktop](https://lbry.com/get)\ -Search => [SearXNG](https://github.com/searxng/searxng), [SearX](https://searx.github.io/searx/), [Whoogle](https://benbusby.com/projects/whoogle-search/), [Librex](https://github.com/hnhx/librex/)\ +Search => [SearXNG](https://github.com/searxng/searxng), [SearX](https://searx.github.io/searx/), [Whoogle](https://benbusby.com/projects/whoogle-search/), [LibreX](https://github.com/hnhx/librex/)\ Translate => [SimplyTranslate](https://git.sr.ht/~metalune/simplytranslate_web), [LingvaTranslate](https://github.com/TheDavidDelta/lingva-translate)\ Maps => [OpenStreetMap](https://www.openstreetmap.org/), [FacilMap](https://github.com/FacilMap/facilmap)\ Send Files => [Send](https://gitlab.com/timvisee/send) diff --git a/package.json b/package.json index e6214c85..50872aac 100644 --- a/package.json +++ b/package.json @@ -22,12 +22,13 @@ "bugs": { "url": "https://github.com/LibRedirect/LibRedirect/issues" }, - "homepage": "https://github.com/LibRedirect/LibRedirect", + "homepage": "https://libredirect.github.io", "devDependencies": { "prettier": "2.7.1", "web-ext": "^6.7.0" }, "dependencies": { - "buffer": "^6.0.3" + "buffer": "^6.0.3", + "ejs": "^3.1.8" } } diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js index 52848de7..929b5c17 100644 --- a/src/assets/javascripts/utils.js +++ b/src/assets/javascripts/utils.js @@ -25,13 +25,15 @@ function getRandomInstance(instances) { let cloudflareBlackList = [] let authenticateBlackList = [] -async function initcloudflareBlackList() { +let offlineBlacklist = [] +async function initBlackList() { return new Promise(resolve => { fetch("/instances/blacklist.json") .then(response => response.text()) .then(data => { cloudflareBlackList = JSON.parse(data).cloudflare authenticateBlackList = JSON.parse(data).authenticate + offlineBlacklist = JSON.parse(data).offlineBlacklist resolve() }) }) @@ -53,7 +55,7 @@ function updateInstances() { return } } - await initcloudflareBlackList() + await initBlackList() const instances = JSON.parse(http.responseText) youtubeHelper.setRedirects({ @@ -114,7 +116,7 @@ async function processDefaultCustomInstances(target, name, protocol, document) { let nameCustomInstances = [] let nameCheckListElement = nameProtocolElement.getElementsByClassName("checklist")[0] - await initcloudflareBlackList() + await initBlackList() let nameDefaultRedirects @@ -162,6 +164,7 @@ async function processDefaultCustomInstances(target, name, protocol, document) { ...redirects[name][protocol].map(x => { const cloudflare = cloudflareBlackList.includes(x) ? ' cloudflare' : "" const authenticate = authenticateBlackList.includes(x) ? ' authenticate' : "" + const offline = offlineBlacklist.includes(x) ? ' offline' : "" let ms = instancesLatency[x] let latencyColor = ms <= 1000 ? "green" : ms <= 2000 ? "orange" : "red" @@ -172,7 +175,7 @@ async function processDefaultCustomInstances(target, name, protocol, document) { const latency = x in instancesLatency ? '' + latencyLimit + "" : "" - let warnings = [cloudflare, authenticate, latency].join(" ") + let warnings = [cloudflare, authenticate, offline, latency].join(" ") return `
${x}${warnings} diff --git a/src/instances/get_instances.py b/src/instances/get_instances.py index 0d0e8c78..07adbceb 100644 --- a/src/instances/get_instances.py +++ b/src/instances/get_instances.py @@ -89,6 +89,19 @@ def is_authenticate(url): return False return False +def is_offline(url): + try: + r = requests.get(url, timeout=5) + if r.status_code != 200: + print(url + ' is ' + Fore.RED + 'offline' + Style.RESET_ALL) + print("Status code") + print(r.status_code) + return True + else: + return False + except: + return False + def invidious(): r = requests.get('https://api.invidious.io/instances.json') @@ -635,6 +648,7 @@ mightyList = filterLastSlash(mightyList) cloudflare = [] authenticate = [] +offline = [] for k1, v1 in mightyList.items(): if type(mightyList[k1]) is dict: for k2, v2 in mightyList[k1].items(): @@ -647,12 +661,15 @@ for k1, v1 in mightyList.items(): cloudflare.append(instance) if not instance.endswith('.onion') and not instance.endswith('.i2p') and not instance.endswith('.loki') and is_authenticate(instance): authenticate.append(instance) + if not instance.endswith('.onion') and not instance.endswith('.i2p') and not instance.endswith('.loki') and is_offline(instance): + offline.append(instance) peertube() blacklist = { 'cloudflare': cloudflare, - 'authenticate': authenticate + 'authenticate': authenticate, + 'offline': offline } # Writing to file diff --git a/src/pages/options/widgets/general.js b/src/pages/options/widgets/general.js index 5407159d..56439a95 100644 --- a/src/pages/options/widgets/general.js +++ b/src/pages/options/widgets/general.js @@ -156,6 +156,15 @@ protocolFallbackCheckbox.addEventListener("change", event => { browser.storage.local.set({ protocolFallback: event.target.checked }) }) +let latencyOutput = document.getElementById("latency-output") +let latencyInput = document.getElementById("latency-input") +latencyInput.addEventListener("change", event => { + browser.storage.local.set({ latencyThreshold: event.target.value}) +}) +latencyInput.addEventListener("input", event => { + latencyOutput.value = event.target.value +}) + let nameCustomInstanceInput = document.getElementById("exceptions-custom-instance") let instanceTypeElement = document.getElementById("exceptions-custom-instance-type") let instanceType = "url" @@ -181,6 +190,7 @@ browser.storage.local.get( "exceptions", "protocol", "protocolFallback", + "latencyThreshold", // 'firstPartyIsolate' ], r => { @@ -188,6 +198,7 @@ browser.storage.local.get( themeElement.value = r.theme protocolElement.value = r.protocol protocolFallbackCheckbox.checked = r.protocolFallback + latencyOutput.value = r.latencyThreshold // firstPartyIsolate.checked = r.firstPartyIsolate; let protocolFallbackElement = document.getElementById("protocol-fallback") diff --git a/src/pages/widgets/links.pug b/src/pages/widgets/links.pug index cac2ecb3..c7f8e0a6 100644 --- a/src/pages/widgets/links.pug +++ b/src/pages/widgets/links.pug @@ -31,7 +31,7 @@ mixin links(service) a(href="#reddit" data-localise="__MSG_reddit__") Reddit .title - img(src="../../../assets/images/imgur-icon.png") + img(src="../../../assets/images/imgur.png") a(href="#imgur" data-localise="__MSG_imgur__") Imgur .title @@ -60,7 +60,7 @@ mixin links(service) .title img(src="../../../assets/images/lbry-icon.png") - a(href="#lbry" data-localise="__MSG_lbry__") LBRY/Odysee + a(href="#lbry" data-localise="__MSG_lbry__") LBRY .title +search @@ -80,4 +80,4 @@ mixin links(service) .title +about - a(href="#about" data-localise="__MSG_about") About \ No newline at end of file + a(href="#about" data-localise="__MSG_about") About -- cgit 1.4.1 From df563552e32e66d860d2ab42d48fd12bb975f35f Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Wed, 27 Jul 2022 16:13:53 +0000 Subject: Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index a9e68391..4de39765 100644 --- a/README.md +++ b/README.md @@ -101,7 +101,7 @@ npm run start ### Install temporarily open `about:addons`\ -click on the settings button below the addon search bar and select `debug add-on`\ +type in the address bar `about:debugging`\ press `load temporarily addon` ### Install in Firefox ESR, Developer Edition, Nightly -- cgit 1.4.1 From 1a8e130d18787d15ab648c2f5bef7bf2b237211b Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Wed, 3 Aug 2022 13:18:25 +0200 Subject: Update 'README.md' --- README.md | 3 --- 1 file changed, 3 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 4de39765..db740eb0 100644 --- a/README.md +++ b/README.md @@ -7,9 +7,6 @@ A web extension that redirects YouTube, Twitter, Instagram... requests to altern [![LibrePay Badge](https://img.shields.io/liberapay/gives/libredirect?label=Liberapay)](https://liberapay.com/LibRedirect) [![Firefox Add-on](./img/badge-amo.png)](https://addons.mozilla.org/firefox/addon/libredirect/)  - - -  -- cgit 1.4.1 From a72a32612032280fb994c7f4495ca153123ac5c7 Mon Sep 17 00:00:00 2001 From: Hygna Date: Sun, 18 Sep 2022 17:13:07 +0100 Subject: Rollback master to pre-OOP --- .woodpecker/instances.yml | 23 +++++++++++++++++++++++ README.md | 2 +- src/instances/beatbump.json | 7 ++----- src/instances/bibliogram.json | 6 ++++++ src/instances/get_instances.py | 13 +++---------- 5 files changed, 35 insertions(+), 16 deletions(-) create mode 100644 .woodpecker/instances.yml create mode 100644 src/instances/bibliogram.json (limited to 'README.md') diff --git a/.woodpecker/instances.yml b/.woodpecker/instances.yml new file mode 100644 index 00000000..96fe59f6 --- /dev/null +++ b/.woodpecker/instances.yml @@ -0,0 +1,23 @@ +pipeline: + instancefetch: + image: python:3.8 + secrets: [token, mail] + when: + event: cron + commands: + - python -m pip install --upgrade pip + - pip install requests bs4 colorama + - python src/instances/get_instances.py + # Git configuration + - git config --global user.email $MAIL + - git config --global user.name "Woodpecker CI" + - git commit -am "updated instances" + - mkdir ~/.ssh + - ssh-keyscan -t ed25519 codeberg.org >> ~/.ssh/known_hosts + - git remote set-url origin git@codeberg.org:libredirect/libredirect.git + #- echo $TOKEN > key + #- chmod 0600 key + - eval `ssh-agent` + - echo "$TOKEN" | tr -d '\r' | ssh-add - + #- ssh-add key + - git push --set-upstream origin master diff --git a/README.md b/README.md index db740eb0..c97a20ff 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Send Files => [Send](https://gitlab.com/timvisee/send) **Note**: The Extension will be using random instances by default. You can modify this and add custom instances too. -[FAQ](https://libredirect.github.io/faq.html) +# Please read the [FAQ](https://libredirect.github.io/faq.html) if you have any questions! ## Donate diff --git a/src/instances/beatbump.json b/src/instances/beatbump.json index df5a20f7..e09273dd 100644 --- a/src/instances/beatbump.json +++ b/src/instances/beatbump.json @@ -1,9 +1,6 @@ { - "normal": [ - "https://beatbump.ml", - "https://beatbump.esmailelbob.xyz" - ], - "tor": [], + "normal": ["https://beatbump.ml", "https://beatbump.esmailelbob.xyz"], + "tor": ["http://beatbump.esmail5pdn24shtvieloeedh7ehz3nrwcdivnfhfcedl7gf4kwddhkqd.onion"], "i2p": [], "loki": [] } diff --git a/src/instances/bibliogram.json b/src/instances/bibliogram.json new file mode 100644 index 00000000..d72f2129 --- /dev/null +++ b/src/instances/bibliogram.json @@ -0,0 +1,6 @@ +{ + "normal": ["https://bibliogram.1d4.us", "https://bibliogram.froth.zone", "https://ig.tokhmi.xyz", "https://ig.beparanoid.de", "https://bibliogram.priv.pw"], + "tor": [], + "i2p": [], + "loki": [] +} diff --git a/src/instances/get_instances.py b/src/instances/get_instances.py index 085d7273..250dd258 100644 --- a/src/instances/get_instances.py +++ b/src/instances/get_instances.py @@ -230,16 +230,9 @@ def nitter(): def bibliogram(): - r = requests.get('https://bibliogram.art/api/instances') - rJson = json.loads(r.text) - bibliogramList = {} - bibliogramList['normal'] = [] - bibliogramList['tor'] = [] - bibliogramList['i2p'] = [] - bibliogramList['loki'] = [] - for item in rJson['data']: - bibliogramList['normal'].append(item['address']) - mightyList['bibliogram'] = bibliogramList + json_object = json.dumps(mightyList, ensure_ascii=False, indent=2) + with open('./src/instances/bibliogram.json') as file: + mightyList['bibliogram'] = json.load(file) print(Fore.GREEN + 'Fetched ' + Style.RESET_ALL + 'Bibliogram') -- cgit 1.4.1 From 800d0cbd9fd4286f0affcb5a28f01f03532655fb Mon Sep 17 00:00:00 2001 From: Hygna Date: Wed, 28 Sep 2022 20:18:32 +0100 Subject: Unify cookies --- README.md | 14 ++--- package.json | 2 - src/assets/javascripts/general.js | 6 +- src/assets/javascripts/services.js | 41 ++++++++----- src/assets/javascripts/utils.js | 106 +++++++++++++++++----------------- src/config/config.json | 2 +- src/pages/background/background.js | 2 +- src/pages/options/index.html | 2 +- src/pages/options/init.js | 4 +- src/pages/options/widgets/general.ejs | 2 +- src/pages/popup/popup.html | 2 +- src/pages/popup/popup.js | 10 ++-- 12 files changed, 99 insertions(+), 94 deletions(-) (limited to 'README.md') diff --git a/README.md b/README.md index 4de39765..2c06b0a2 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Imgur => [Rimgo](https://codeberg.org/video-prize-ranch/rimgo)\ Wikipedia => [Wikiless](https://codeberg.org/orenom/wikiless)\ Medium => [Scribe](https://sr.ht/~edwardloveall/scribe/)\ Quora => [Quetre](https://github.com/zyachel/quetre)\ -IMDb => [Libremdb](https://github.com/zyachel/libremdb)\ +IMDb => [libremdb](https://github.com/zyachel/libremdb)\ PeerTube => [SimpleerTube](https://git.sr.ht/~metalune/simpleweb_peertube)\ LBRY/Odysee => [Librarian](https://codeberg.org/librarian/librarian), [LBRY Desktop](https://lbry.com/get)\ Search => [SearXNG](https://github.com/searxng/searxng), [SearX](https://searx.github.io/searx/), [Whoogle](https://benbusby.com/projects/whoogle-search/), [LibreX](https://github.com/hnhx/librex/)\ @@ -72,21 +72,19 @@ npm update npm install ``` -If you are modifying any files ending with .pug, the pug cli needs to be installed with the following command (with root privileges): +If you are modifying any files ending with .ejs, you need to run the following command to render html: ``` -npm install -g pug-cli +npm run ejs ``` -and then run `npm run pug` to generate pages in the background. - -### Build +### Build the extention zip archive: ``` npm run build ``` -### Test +### Run automated tests ``` npm run test @@ -120,4 +118,4 @@ select `load unpacked extension`\ select `src` folder [Privacy Policy](Privacy-Policy.md)\ -Credits: [Privacy Redirect](https://github.com/SimonBrazell/privacy-redirect) +Forked from [Privacy Redirect](https://github.com/SimonBrazell/privacy-redirect) diff --git a/package.json b/package.json index 76f57474..ec39aee4 100644 --- a/package.json +++ b/package.json @@ -9,8 +9,6 @@ "start": "web-ext run --browser-console --source-dir ./src/", "build": "web-ext build --overwrite-dest --source-dir ./src/", "test": "web-ext lint --source-dir ./src/ || true", - "pug": "pug ./src/pages/options/*.pug ./src/pages/popup/ -P -w", - "prettier": "npx prettier --write .", "instances": "python3 src/instances/get_instances.py; git update-index --assume-unchanged src/instances/blacklist.json src/instances/data.json", "ejs": "npx ejs src/pages/options/index.ejs -f src/config/config.json -o src/pages/options/index.html; npx ejs src/pages/popup/popup.ejs -f src/config/config.json -o src/pages/popup/popup.html" }, diff --git a/src/assets/javascripts/general.js b/src/assets/javascripts/general.js index 3a8987ac..9dcba752 100644 --- a/src/assets/javascripts/general.js +++ b/src/assets/javascripts/general.js @@ -11,8 +11,8 @@ function isException(url) { function init() { return new Promise(resolve => { - browser.storage.local.get("exceptions", r => { - exceptions = r.exceptions + browser.storage.local.get("options", r => { + exceptions = r.options.exceptions resolve() }) }) @@ -30,7 +30,7 @@ async function initDefaults() { url: [], regex: [], }, - theme: "DEFAULT", + theme: "detect", popupServices: ["youtube", "twitter", "instagram", "tiktok", "imgur", "reddit", "quora", "translate", "maps"], autoRedirect: false, firstPartyIsolate: false, diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 9fc5a0a3..3db12595 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -19,25 +19,28 @@ function init() { return new Promise(async resolve => { // await getConfig() browser.storage.local.get(["options", "targets", "redirects", "blacklists"], r => { - blacklists = r.blacklists - redirects = r.redirects - targets = r.targets - options = r.options + if (r.options) { + blacklists = r.blacklists + redirects = r.redirects + targets = r.targets + options = r.options + } resolve() }) }) } -await init() await getConfig() +await init() function fetchFrontendInstanceList(service, frontend) { let tmp = [] - if (!config.services[service].frontends[frontend].singleInstance) { + if (config.services[service].frontends[frontend].instanceList) { for (const network in config.networks) { + if (!redirects[frontend]) console.log(frontend) tmp.push(...redirects[frontend][network], ...options[frontend][network].custom) } - } else if (config.services[service].frontends[frontend].singleInstance != undefined) tmp = config.services[service].frontends[frontend].singleInstance + } else if (config.services[service].frontends[frontend].singleInstance) tmp = config.services[service].frontends[frontend].singleInstance return tmp } @@ -58,8 +61,8 @@ function all(service, frontend) { function regexArray(service, url) { let targets if (config.services[service].targets == "datajson") { - browser.storage.local.get(`${service}Targets`, r => { - targets = r[service + "Targets"] + browser.storage.local.get("targets", r => { + targets = r.targets[service] }) } else { targets = config.services[service].targets @@ -397,8 +400,10 @@ function initDefaults() { let redirects = JSON.parse(data) let options = r.options let targets = {} + // let latency = {} for (const service in config.services) { options[service] = {} + // latency[service] = {} if (config.services[service].targets == "datajson") { targets[service] = redirects[service] //delete dataJson[service] @@ -423,19 +428,25 @@ function initDefaults() { } } } - browser.storage.local.set({ redirects, options, targets }) + browser.storage.local.set({ redirects, options, targets /*, latency*/ }) resolve() }) }) }) } -function computeService(url) { +function computeService(url, returnFrontend) { for (const service in config.services) { if (regexArray(service, url)) { - return service - } else if (all(service).includes(utils.protocolHost(url))) { - return service + if (returnFrontend) return [service, null] + else return service + } else { + for (const frontend in config.services[service].frontends) { + if (all(service, frontend).includes(utils.protocolHost(url))) { + if (returnFrontend) return [service, frontend] + else return service + } + } } } return null @@ -524,7 +535,7 @@ function unifyPreferences(url) { const frontend = config.services[currentService].frontends[currentFrontend] if ("cookies" in frontend.preferences) { - for (const cookie in frontend.preferences.cookies) { + for (const cookie of frontend.preferences.cookies) { await utils.copyCookie(currentFrontend, url, instancesList, cookie) } } diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js index 0e8acb3c..70a93240 100644 --- a/src/assets/javascripts/utils.js +++ b/src/assets/javascripts/utils.js @@ -111,29 +111,27 @@ function protocolHost(url) { return `${url.protocol}//${url.host}` } -async function processDefaultCustomInstances(target, name, protocol, document) { - let latencyKey = `${name}Latency` +async function processDefaultCustomInstances(service, name, network, document) { let instancesLatency - let nameProtocolElement = document.getElementById(name).getElementsByClassName(protocol)[0] + let nameNetworkElement = document.getElementById(name).getElementsByClassName(network)[0] let nameCustomInstances = [] - let nameCheckListElement = nameProtocolElement.getElementsByClassName("checklist")[0] + let nameCheckListElement = nameNetworkElement.getElementsByClassName("checklist")[0] await initBlackList() let nameDefaultRedirects - let redirectsChecks = `${name}${camelCase(protocol)}RedirectsChecks` - let customRedirects = `${name}${camelCase(protocol)}CustomRedirects` - - let redirects + let redirects, options async function getFromStorage() { return new Promise(async resolve => - browser.storage.local.get([redirectsChecks, customRedirects, "redirects", latencyKey], r => { - nameDefaultRedirects = r[redirectsChecks] - nameCustomInstances = r[customRedirects] - instancesLatency = r[latencyKey] ?? [] + browser.storage.local.get(["options", "redirects", "latency"], r => { + nameDefaultRedirects = r.options[name][network].enabled + nameCustomInstances = r.options[name][network].custom + options = r.options + if (r.latency) instancesLatency = r.latency[name] ?? [] + else instancesLatency = [] redirects = r.redirects resolve() }) @@ -141,12 +139,11 @@ async function processDefaultCustomInstances(target, name, protocol, document) { } await getFromStorage() - if (nameCustomInstances === undefined) console.log(customRedirects) function calcNameCheckBoxes() { let isTrue = true - for (const item of redirects[name][protocol]) { - if (nameDefaultRedirects === undefined) console.log(name + protocol + " is undefined") + for (const item of redirects[name][network]) { + if (nameDefaultRedirects === undefined) console.log(name + network + " is undefined") if (!nameDefaultRedirects.includes(item)) { isTrue = false break @@ -156,14 +153,14 @@ async function processDefaultCustomInstances(target, name, protocol, document) { element.checked = nameDefaultRedirects.includes(element.className) } if (nameDefaultRedirects.length == 0) isTrue = false - nameProtocolElement.getElementsByClassName("toggle-all")[0].checked = isTrue + nameNetworkElement.getElementsByClassName("toggle-all")[0].checked = isTrue } nameCheckListElement.innerHTML = [ `
Toggle All
`, - ...redirects[name][protocol].map(x => { + ...redirects[name][network].map(x => { const cloudflare = cloudflareBlackList.includes(x) ? ' cloudflare' : "" const authenticate = authenticateBlackList.includes(x) ? ' authenticate' : "" const offline = offlineBlackList.includes(x) ? ' offline' : "" @@ -188,31 +185,32 @@ async function processDefaultCustomInstances(target, name, protocol, document) { localise.localisePage() calcNameCheckBoxes() - nameProtocolElement.getElementsByClassName("toggle-all")[0].addEventListener("change", async event => { - if (event.target.checked) nameDefaultRedirects = [...redirects[name][protocol]] + nameNetworkElement.getElementsByClassName("toggle-all")[0].addEventListener("change", async event => { + if (event.service.checked) nameDefaultRedirects = [...redirects[name][network]] else nameDefaultRedirects = [] - browser.storage.local.set({ [redirectsChecks]: nameDefaultRedirects }) + options[service][network].enabled = nameDefaultRedirects + browser.storage.local.set({ options }) calcNameCheckBoxes() }) for (let element of nameCheckListElement.getElementsByTagName("input")) { if (element.className != "toggle-all") - nameProtocolElement.getElementsByClassName(element.className)[0].addEventListener("change", async event => { - if (event.target.checked) nameDefaultRedirects.push(element.className) + nameNetworkElement.getElementsByClassName(element.className)[0].addEventListener("change", async event => { + if (event.service.checked) nameDefaultRedirects.push(element.className) else { let index = nameDefaultRedirects.indexOf(element.className) if (index > -1) nameDefaultRedirects.splice(index, 1) } - browser.storage.local.set({ - [redirectsChecks]: nameDefaultRedirects, - }) + + options[service][network].enabled = nameDefaultRedirects + browser.storage.local.set({ options }) calcNameCheckBoxes() }) } function calcNameCustomInstances() { - nameProtocolElement.getElementsByClassName("custom-checklist")[0].innerHTML = nameCustomInstances + nameNetworkElement.getElementsByClassName("custom-checklist")[0].innerHTML = nameCustomInstances .map( x => `
${x} @@ -227,24 +225,26 @@ async function processDefaultCustomInstances(target, name, protocol, document) { .join("\n") for (const item of nameCustomInstances) { - nameProtocolElement.getElementsByClassName(`clear-${item}`)[0].addEventListener("click", async () => { + nameNetworkElement.getElementsByClassName(`clear-${item}`)[0].addEventListener("click", async () => { let index = nameCustomInstances.indexOf(item) if (index > -1) nameCustomInstances.splice(index, 1) - browser.storage.local.set({ [customRedirects]: nameCustomInstances }) + options[service][network].custom = nameCustomInstances + browser.storage.local.set({ options }) calcNameCustomInstances() }) } } calcNameCustomInstances() - nameProtocolElement.getElementsByClassName("custom-instance-form")[0].addEventListener("submit", async event => { + nameNetworkElement.getElementsByClassName("custom-instance-form")[0].addEventListener("submit", async event => { event.preventDefault() - let nameCustomInstanceInput = nameProtocolElement.getElementsByClassName("custom-instance")[0] + let nameCustomInstanceInput = nameNetworkElement.getElementsByClassName("custom-instance")[0] let url = new URL(nameCustomInstanceInput.value) let protocolHostVar = protocolHost(url) - if (nameCustomInstanceInput.validity.valid && !redirects[name][protocol].includes(protocolHostVar)) { + if (nameCustomInstanceInput.validity.valid && !redirects[name][network].includes(protocolHostVar)) { if (!nameCustomInstances.includes(protocolHostVar)) { nameCustomInstances.push(protocolHostVar) - browser.storage.local.set({ [customRedirects]: nameCustomInstances }) + options[service][network].custom = nameCustomInstances + browser.storage.local.set({ options }) nameCustomInstanceInput.value = "" } calcNameCustomInstances() @@ -299,9 +299,9 @@ async function testLatency(element, instances, frontend) { let myList = {} let latencyThreshold let redirectsChecks = [] - browser.storage.local.get(["latencyThreshold", `${frontend}ClearnetRedirectsChecks`], r => { - latencyThreshold = r.latencyThreshold - redirectsChecks = r[`${frontend}ClearnetRedirectsChecks`] + browser.storage.local.get(["options"], r => { + latencyThreshold = r.options.latencyThreshold + redirectsChecks = r.options[frontend].clearnet.enabled }) for (const href of instances) await ping(href).then(time => { @@ -331,9 +331,9 @@ async function testLatency(element, instances, frontend) { function copyCookie(frontend, targetUrl, urls, name) { return new Promise(resolve => { - browser.storage.local.get("firstPartyIsolate", r => { + browser.storage.local.get("options", r => { let query - if (!r.firstPartyIsolate) + if (!r.options.firstPartyIsolate) query = { url: protocolHost(targetUrl), name: name, @@ -348,7 +348,7 @@ function copyCookie(frontend, targetUrl, urls, name) { for (const cookie of cookies) if (cookie.name == name) { for (const url of urls) { - const setQuery = r.firstPartyIsolate + const setQuery = r.options.firstPartyIsolate ? { url: url, name: name, @@ -375,23 +375,21 @@ function copyCookie(frontend, targetUrl, urls, name) { function getPreferencesFromToken(frontend, targetUrl, urls, name, endpoint) { return new Promise(resolve => { - browser.storage.local.get("firstPartyIsolate", r => { + const http = new XMLHttpRequest() + const url = `${targetUrl}${endpoint}` + http.open("GET", url, false) + //http.setRequestHeader("Cookie", `${name}=${cookie.value}`) + http.send(null) + const preferences = JSON.parse(http.responseText) + let formdata = new FormData() + for (var key in preferences) formdata.append(key, preferences[key]) + for (const url of urls) { const http = new XMLHttpRequest() - const url = `${targetUrl}${endpoint}` - http.open("GET", url, false) - http.setRequestHeader("Cookie", `${name}=${cookie.value}`) + http.open("POST", `${url}/settings/stay`, false) http.send(null) - const preferences = JSON.parse(http.responseText) - let formdata = new FormData() - for (var key in preferences) formdata.append(key, preferences[key]) - for (const url of urls) { - const http = new XMLHttpRequest() - http.open("POST", `${url}/settings/stay`, false) - http.send(null) - } - resolve() - return - }) + } + resolve() + return }) } @@ -427,7 +425,7 @@ function copyRaw(test, copyRawElement) { }) } -function unify(test) { +function unify() { return new Promise(resolve => { browser.tabs.query({ active: true, currentWindow: true }, async tabs => { let currTab = tabs[0] diff --git a/src/config/config.json b/src/config/config.json index 09774895..6f926034 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -184,7 +184,7 @@ "instanceList": true } }, - "targets": ["^https?:\\/{2}(www\\.)?instagram\\.com"], + "targets": ["^https?:\\/{2}(www\\.)?instagram\\.com\\/p\\/"], "name": "Instagram", "options": { "enabled": true }, "imageType": "png", diff --git a/src/pages/background/background.js b/src/pages/background/background.js index 241b51de..e9bf691f 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -121,7 +121,7 @@ async function redirectOfflineInstance(url, tabId) { let counter = 0 function isAutoRedirect() { - return new Promise(resolve => browser.storage.local.get("autoRedirect", r => resolve(r.autoRedirect == true))) + return new Promise(resolve => browser.storage.local.get("options", r => resolve(r.options.autoRedirect == true))) } browser.webRequest.onResponseStarted.addListener( diff --git a/src/pages/options/index.html b/src/pages/options/index.html index 20592637..6ef33723 100644 --- a/src/pages/options/index.html +++ b/src/pages/options/index.html @@ -99,7 +99,7 @@

Theme

diff --git a/src/pages/options/init.js b/src/pages/options/init.js index 5b679da4..cac23748 100644 --- a/src/pages/options/init.js +++ b/src/pages/options/init.js @@ -4,8 +4,8 @@ import localise from "../../assets/javascripts/localise.js" function changeTheme() { return new Promise(resolve => { - browser.storage.local.get("theme", r => { - switch (r.theme) { + browser.storage.local.get("options", r => { + switch (r.options.theme) { case "dark": document.body.classList.add("dark-theme") document.body.classList.remove("light-theme") diff --git a/src/pages/options/widgets/general.ejs b/src/pages/options/widgets/general.ejs index fa85e8bc..8f7ab029 100644 --- a/src/pages/options/widgets/general.ejs +++ b/src/pages/options/widgets/general.ejs @@ -6,7 +6,7 @@

Theme

diff --git a/src/pages/popup/popup.html b/src/pages/popup/popup.html index e21a63a0..d52a34b6 100644 --- a/src/pages/popup/popup.html +++ b/src/pages/popup/popup.html @@ -241,7 +241,7 @@
-
+

Unify Settings

diff --git a/src/pages/popup/popup.js b/src/pages/popup/popup.js index 098ae01a..5a5ccb53 100644 --- a/src/pages/popup/popup.js +++ b/src/pages/popup/popup.js @@ -78,11 +78,11 @@ browser.storage.local.get("options", r => { return } - const currentService = serviceHelper.computeService(url) - if (currentService != null) { - divs[currentService].current.classList.remove("hide") - divs[currentService].all.classList.add("hide") - if (config.services[currentService].preferences != undefined) { + const [service, frontend] = serviceHelper.computeService(url, true) + if (service) { + divs[service].current.classList.remove("hide") + divs[service].all.classList.add("hide") + if (config.services[service].frontends[frontend].preferences) { const unify = document.getElementById("unify") const textElement = document.getElementById("unify").getElementsByTagName("h4")[0] unify.addEventListener("click", () => { -- cgit 1.4.1 From c87bbba349ced5cbc5d9559fbf8af88f9557ad24 Mon Sep 17 00:00:00 2001 From: Hygna Date: Tue, 4 Oct 2022 19:10:07 +0100 Subject: Ported 87d68cb662 --- .woodpecker/instances.yml | 9 +- README.md | 4 +- src/assets/javascripts/frontend.js | 143 ----------------- src/assets/javascripts/services.js | 18 ++- src/pages/background/background.js | 314 ++++--------------------------------- 5 files changed, 54 insertions(+), 434 deletions(-) delete mode 100644 src/assets/javascripts/frontend.js (limited to 'README.md') diff --git a/.woodpecker/instances.yml b/.woodpecker/instances.yml index 72fdd6e7..43df0cd9 100644 --- a/.woodpecker/instances.yml +++ b/.woodpecker/instances.yml @@ -8,13 +8,14 @@ pipeline: - python -m pip install --upgrade pip - pip install requests colorama - python src/instances/get_instances.py + # SSH configuration + - mkdir ~/.ssh + - ssh-keyscan -t ed25519 codeberg.org >> ~/.ssh/known_hosts + - eval `ssh-agent` + - echo "$TOKEN" | tr -d '\r' | ssh-add - # Git configuration - git config --global user.email $MAIL - git config --global user.name "Woodpecker CI" - git commit -am "updated instances" - - mkdir ~/.ssh - - ssh-keyscan -t ed25519 codeberg.org >> ~/.ssh/known_hosts - git remote set-url origin git@codeberg.org:libredirect/libredirect.git - - eval `ssh-agent` - - echo "$TOKEN" | tr -d '\r' | ssh-add - - git push --set-upstream origin master diff --git a/README.md b/README.md index d55dd37b..8c5d6080 100644 --- a/README.md +++ b/README.md @@ -36,7 +36,7 @@ Send Files => [Send](https://gitlab.com/timvisee/send) **Note**: The Extension will be using random instances by default. You can modify this and add custom instances too. -# Please read the [FAQ](https://libredirect.github.io/faq.html) if you have any questions! +# Please read the [FAQ](https://libredirect.codeberg.page/faq.html) if you have any questions! ## Donate @@ -69,7 +69,7 @@ npm update npm install ``` -If you are modifying any files ending with .ejs, you need to run the following command to render html: +If you are modifying `config.json` or any files ending with .ejs, you need to run the following command to render html: ``` npm run ejs diff --git a/src/assets/javascripts/frontend.js b/src/assets/javascripts/frontend.js deleted file mode 100644 index ab71cc0d..00000000 --- a/src/assets/javascripts/frontend.js +++ /dev/null @@ -1,143 +0,0 @@ -class FrontEnd { - constructor({ enable, frontends, frontend, redirect }) { - this.redirects = {} - this.enable = enable - this.frontend = frontend - this.protocol = "normal" - this.protocolFallback = true - fetch("/instances/data.json") - .then(response => response.text()) - .then(async data => { - data = JSON.parse(data) - fetch("/instances/blacklist.json") - .then(response => response.text()) - .then(async blackList => { - blackList = JSON.parse(blackList) - for (const frontend in frontends) { - this.redirects[frontend] = {} - - this.redirects[frontend].cookies = [...frontends[frontend].cookies] - - for (const protocol in data[frontend]) { - this.redirects[frontend][protocol] = {} - - this.redirects[frontend][protocol].all = [...data[frontend][protocol]] - - this.redirects[frontend][protocol].custom = [] - - this.redirects[frontend][protocol].checked = [...data[frontend][protocol]] - for (const instance of blackList.cloudflare) { - const a = this.redirects[frontend][protocol].checked.indexOf(instance) - if (a > -1) this.redirects[frontend][protocol].checked.splice(a, 1) - } - for (const instance of blackList.offline) { - const a = this.redirects[frontend][protocol].checked.indexOf(instance) - if (a > -1) this.redirects[frontend][protocol].checked.splice(a, 1) - } - } - } - }) - }) - this.unifyCookies = from => - new Promise(async resolve => { - await init() - const protocolHost = utils.protocolHost(from) - const list = [...this.redirects[this.frontend][this.protocol]] - if (![...list.checked, ...list.custom].includes(protocolHost)) { - resolve() - return - } - for (const cookie of this.redirects[this.frontend].cookies) { - await utils.copyCookie(frontend, protocolHost, [...list.checked, list.custom], cookie) - } - resolve(true) - }) - - this.switchInstance = (url, disableOverride) => { - if (!this.enable && !disableOverride) return - - const protocolHost = utils.protocolHost(url) - - const list = [...this.redirects[this.frontend][this.protocol]] - if (!list.all.includes(protocolHost)) return - - let userList = [...list.checked, ...list.custom] - if (userList.length === 0 && this.protocolFallback) userList = [...list.normal.all] - - const i = userList.indexOf(protocolHost) - if (i > -1) userList.splice(i, 1) - if (userList.length === 0) return - - const randomInstance = utils.getRandomInstance(userList) - return `${randomInstance}${url.pathname}${url.search}` - } - - this.redirect = (url, type, initiator, disableOverride) => { - const result = redirect(url, type, initiator, disableOverride) - if (result == "BYPASSTAB") return "BYPASSTAB" - if (result) { - const list = [...this.redirects[this.frontend][this.protocol]] - let userList = [...list.checked, ...list.custom] - const randomInstance = utils.getRandomInstance(userList) - return `${randomInstance}${result.pathname}${result.search}` - } - } - - let init = () => new Promise(async resolve => {}) - } -} - -let Reddit = new FrontEnd({ - enable: true, - frontends: { - libreddit: { cookies: ["theme", "front_page", "layout", "wide", "post_sort", "comment_sort", "show_nsfw", "autoplay_videos", "use_hls", "hide_hls_notification", "subscriptions", "filters"] }, - teddit: { - cookies: [ - "collapse_child_comments", - "domain_instagram", - "domain_twitter", - "domain_youtube", - "flairs", - "highlight_controversial", - "nsfw_enabled", - "post_media_max_height", - "show_upvoted_percentage", - "show_upvotes", - "theme", - "videos_muted", - ], - }, - }, - frontend: "libreddit", - redirect: (url, type, initiator, disableOverride) => { - if (this.enable && !disableOverride) return - - const targets = [/^https?:\/{2}(www\.|old\.|np\.|new\.|amp\.|)reddit\.com/, /^https?:\/{2}(i\.|preview\.)redd\.it/] - if (!targets.some(rx => rx.test(url.href))) return - - if (initiator && all().includes(initiator.origin)) return "BYPASSTAB" - if (!["main_frame", "xmlhttprequest", "other", "image", "media"].includes(type)) return - - const bypassPaths = /\/(gallery\/poll\/rpan\/settings\/topics)/ - if (url.pathname.match(bypassPaths)) return - - const protocolHost = utils.protocolHost(url) - - if (url.host === "i.redd.it") { - if (this.frontend == "libreddit") return `${protocolHost}/img${url.pathname}${url.search}` - if (this.frontend == "teddit") return `${protocolHost}/pics/w:null_${url.pathname.substring(1)}${url.search}` - } else if (url.host === "redd.it") { - // https://redd.it/foo => https://libredd.it/comments/foo - if (this.frontend == "libreddit" && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) return `${protocolHost}/comments${url.pathname}${url.search}` - // https://redd.it/foo => https://teddit.net/comments/foo - if (this.frontend == "teddit" && !url.pathname.match(/^\/+[^\/]+\/+[^\/]/)) return `${protocolHost}/comments${url.pathname}${url.search}` - } else if (url.host === "preview.redd.it") { - if (this.frontend == "libreddit") return `${protocolHost}/preview/pre${url.pathname}${url.search}` - if (this.frontend == "teddit") return - } else { - return `${url.href}` - } - }, -}) - -export default {} diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index afd7906f..eed1e6c6 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -140,13 +140,23 @@ function redirect(url, type, initiator) { case "send": return randomInstance case "nitter": + let search = new URLSearchParams(url.search) + + search.delete("ref_src") + search.delete("ref_url") + + search = search.toString() + if (search !== "") search = `?${search}` + if (url.host.split(".")[0] === "pbs" || url.host.split(".")[0] === "video") { const [, id, format, extra] = url.search.match(/(.*)\?format=(.*)&(.*)/) const query = encodeURIComponent(`${id}.${format}?${extra}`) - return `${randomInstance}/pic${url.pathname}${query}` - } else if (url.pathname.split("/").includes("tweets")) return `${randomInstance}${url.pathname.replace("/tweets", "")}${url.search}` - else if (url.host == "t.co") return `${randomInstance}/t.co${url.pathname}` - else return `${randomInstance}${url.pathname}${url.search}` + return `${randomInstance}/pic${search}${query}` + } + + if (url.pathname.split("/").includes("tweets")) return `${randomInstance}${url.pathname.replace("/tweets", "")}${search}` + if (url.host == "t.co") return `${randomInstance}/t.co${url.pathname}` + return `${randomInstance}${url.pathname}${search}` case "yattee": return url.href.replace(/^https?:\/{2}/, "yattee://") case "freetube": diff --git a/src/pages/background/background.js b/src/pages/background/background.js index 7186144b..cad08580 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -1,68 +1,25 @@ -<<<<<<< HEAD "use strict" import generalHelper from "../../assets/javascripts/general.js" import utils from "../../assets/javascripts/utils.js" - -import youtubeHelper from "../../assets/javascripts/youtube/youtube.js" -import youtubeMusicHelper from "../../assets/javascripts/youtubeMusic.js" -import twitterHelper from "../../assets/javascripts/twitter.js" -import instagramHelper from "../../assets/javascripts/instagram.js" -import redditHelper from "../../assets/javascripts/reddit.js" -import searchHelper from "../../assets/javascripts/search.js" -import translateHelper from "../../assets/javascripts/translate/translate.js" -import mapsHelper from "../../assets/javascripts/maps.js" -import wikipediaHelper from "../../assets/javascripts/wikipedia.js" -import mediumHelper from "../../assets/javascripts/medium.js" -import quoraHelper from "../../assets/javascripts/quora.js" -import libremdbHelper from "../../assets/javascripts/imdb.js" -import reutersHelper from "../../assets/javascripts/reuters.js" -import imgurHelper from "../../assets/javascripts/imgur.js" -import tiktokHelper from "../../assets/javascripts/tiktok.js" -import sendTargetsHelper from "../../assets/javascripts/sendTargets.js" -import peertubeHelper from "../../assets/javascripts/peertube.js" -import lbryHelper from "../../assets/javascripts/lbry.js" - -import frontend from "../../assets/javascripts/frontend.js" +import servicesHelper from "../../assets/javascripts/services.js" window.browser = window.browser || window.chrome -browser.runtime.onInstalled.addListener(details => { - function initDefaults() { +function initDefaults() { + browser.storage.local.clear(() => { fetch("/instances/blacklist.json") .then(response => response.text()) .then(async data => { - browser.storage.local.clear(() => { - browser.storage.local.set({ cloudflareBlackList: JSON.parse(data).cloudflare }, () => { - browser.storage.local.set({ authenticateBlackList: JSON.parse(data).authenticate }, () => { - browser.storage.local.set({ offlineBlackList: JSON.parse(data).offline }, () => { - generalHelper.initDefaults() - youtubeHelper.initDefaults() - youtubeMusicHelper.initDefaults() - twitterHelper.initDefaults() - instagramHelper.initDefaults() - mapsHelper.initDefaults() - searchHelper.initDefaults() - translateHelper.initDefaults() - mediumHelper.initDefaults() - quoraHelper.initDefaults() - libremdbHelper.initDefaults() - reutersHelper.initDefaults() - redditHelper.initDefaults() - wikipediaHelper.initDefaults() - imgurHelper.initDefaults() - tiktokHelper.initDefaults() - sendTargetsHelper.initDefaults() - peertubeHelper.initDefaults() - lbryHelper.initDefaults() - }) - }) - }) + browser.storage.local.set({ blacklists: JSON.parse(data) }, async () => { + await generalHelper.initDefaults() + await servicesHelper.initDefaults() }) }) - } - if (details.reason == "install") initDefaults() + }) +} +browser.runtime.onInstalled.addListener(details => { // if (details.reason == 'install' || (details.reason == "update" && details.previousVersion != browser.runtime.getManifest().version)) { // if (details.reason == "update") // browser.storage.local.get(null, r => { @@ -74,6 +31,25 @@ browser.runtime.onInstalled.addListener(details => { // }) // else initDefaults(); // } + switch (details.reason) { + case "install": + initDefaults() + break + case "update": + fetch("/instances/blacklist.json") + .then(response => response.text()) + .then(async data => { + browser.storage.local.set({ blacklists: JSON.parse(data) }, async () => { + switch (details.previousVersion) { + case "2.2.1": + await generalHelper.initDefaults() + await servicesHelper.initDefaults() + await servicesHelper.upgradeOptions() + break + } + }) + }) + } }) let BYPASSTABs = [] @@ -89,24 +65,7 @@ browser.webRequest.onBeforeRequest.addListener( return null } - let newUrl = youtubeMusicHelper.redirect(url, details.type) - if (!newUrl) newUrl = youtubeHelper.redirect(url, details.type, details.tabId, initiator) - if (!newUrl) newUrl = twitterHelper.redirect(url, details.type, initiator) - if (!newUrl) newUrl = instagramHelper.redirect(url, details.type, initiator) - if (!newUrl) newUrl = mapsHelper.redirect(url, initiator) - if (!newUrl) newUrl = redditHelper.redirect(url, details.type, initiator) - if (!newUrl) newUrl = mediumHelper.redirect(url, details.type, initiator) - if (!newUrl) newUrl = quoraHelper.redirect(url, details.type, initiator) - if (!newUrl) newUrl = libremdbHelper.redirect(url, details.type, initiator) - if (!newUrl) newUrl = reutersHelper.redirect(url, details.type, initiator) - if (!newUrl) newUrl = imgurHelper.redirect(url, details.type, initiator) - if (!newUrl) newUrl = tiktokHelper.redirect(url, details.type, initiator) - if (!newUrl) newUrl = sendTargetsHelper.redirect(url, details.type, initiator) - if (!newUrl) newUrl = peertubeHelper.redirect(url, details.type, initiator) - if (!newUrl) newUrl = lbryHelper.redirect(url, details.type, initiator) - if (!newUrl) newUrl = translateHelper.redirect(url) - if (!newUrl) newUrl = searchHelper.redirect(url) - if (!newUrl) newUrl = wikipediaHelper.redirect(url) + let newUrl = servicesHelper.redirect(url, details.type, initiator) if (details.frameAncestors && details.frameAncestors.length > 0 && generalHelper.isException(new URL(details.frameAncestors[0].url))) newUrl = null @@ -140,6 +99,7 @@ browser.tabs.onRemoved.addListener(tabId => { } }) +/* browser.webRequest.onHeadersReceived.addListener( e => { let response = youtubeHelper.removeXFrameOptions(e) @@ -149,23 +109,10 @@ browser.webRequest.onHeadersReceived.addListener( { urls: [""] }, ["blocking", "responseHeaders"] ) +*/ async function redirectOfflineInstance(url, tabId) { - let newUrl = await youtubeHelper.switchInstance(url, true) - if (!newUrl) newUrl = await twitterHelper.switchInstance(url, true) - if (!newUrl) newUrl = await instagramHelper.switchInstance(url, true) - if (!newUrl) newUrl = await redditHelper.switchInstance(url, true) - if (!newUrl) newUrl = await searchHelper.switchInstance(url, true) - if (!newUrl) newUrl = await translateHelper.switchInstance(url, true) - if (!newUrl) newUrl = await mediumHelper.switchInstance(url, true) - if (!newUrl) newUrl = await quoraHelper.switchInstance(url, true) - if (!newUrl) newUrl = await libremdbHelper.switchInstance(url, true) - if (!newUrl) newUrl = await tiktokHelper.switchInstance(url, true) - if (!newUrl) newUrl = await imgurHelper.switchInstance(url, true) - if (!newUrl) newUrl = await wikipediaHelper.switchInstance(url, true) - if (!newUrl) newUrl = await peertubeHelper.switchInstance(url, true) - if (!newUrl) newUrl = await lbryHelper.switchInstance(url, true) - if (!newUrl) newUrl = await youtubeMusicHelper.switchInstance(url, true) + let newUrl = await servicesHelper.switchInstance(url, true) if (newUrl) { if (counter >= 5) { @@ -182,7 +129,7 @@ async function redirectOfflineInstance(url, tabId) { let counter = 0 function isAutoRedirect() { - return new Promise(resolve => browser.storage.local.get("autoRedirect", r => resolve(r.autoRedirect == true))) + return new Promise(resolve => browser.storage.local.get("options", r => resolve(r.options.autoRedirect == true))) } browser.webRequest.onResponseStarted.addListener( @@ -242,198 +189,3 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => { if (message.function === "unify") utils.unify(false).then(r => sendResponse({ response: r })) return true }) - -browser.storage.local.set({ version: browser.runtime.getManifest().version }) -======= -"use strict" - -import generalHelper from "../../assets/javascripts/general.js" -import utils from "../../assets/javascripts/utils.js" -import servicesHelper from "../../assets/javascripts/services.js" - -window.browser = window.browser || window.chrome - -function initDefaults() { - browser.storage.local.clear(() => { - fetch("/instances/blacklist.json") - .then(response => response.text()) - .then(async data => { - browser.storage.local.set({ blacklists: JSON.parse(data) }, async () => { - await generalHelper.initDefaults() - await servicesHelper.initDefaults() - }) - }) - }) -} - -browser.runtime.onInstalled.addListener(details => { - // if (details.reason == 'install' || (details.reason == "update" && details.previousVersion != browser.runtime.getManifest().version)) { - // if (details.reason == "update") - // browser.storage.local.get(null, r => { - // if (r.theme) { - // const old = encodeURIComponent(JSON.stringify(r)) - // browser.tabs.create({ url: browser.runtime.getURL(`/pages/background/reset_warning.html?data=${old}`) }); - // } - // initDefaults(); - // }) - // else initDefaults(); - // } - switch (details.reason) { - case "install": - initDefaults() - break - case "update": - fetch("/instances/blacklist.json") - .then(response => response.text()) - .then(async data => { - browser.storage.local.set({ blacklists: JSON.parse(data) }, async () => { - switch (details.previousVersion) { - case "2.2.1": - await generalHelper.initDefaults() - await servicesHelper.initDefaults() - await servicesHelper.upgradeOptions() - break - } - }) - }) - } -}) - -let BYPASSTABs = [] -browser.webRequest.onBeforeRequest.addListener( - details => { - const url = new URL(details.url) - if (new RegExp(/^chrome-extension:\/{2}.*\/instances\/.*.json$/).test(url.href) && details.type == "xmlhttprequest") return - let initiator - try { - if (details.originUrl) initiator = new URL(details.originUrl) - else if (details.initiator) initiator = new URL(details.initiator) - } catch { - return null - } - - let newUrl = servicesHelper.redirect(url, details.type, initiator) - - if (details.frameAncestors && details.frameAncestors.length > 0 && generalHelper.isException(new URL(details.frameAncestors[0].url))) newUrl = null - - if (generalHelper.isException(url)) newUrl = "BYPASSTAB" - if (BYPASSTABs.includes(details.tabId)) newUrl = null - - if (newUrl) { - if (newUrl === "CANCEL") { - console.log(`Canceled ${url}`) - return { cancel: true } - } - if (newUrl === "BYPASSTAB") { - console.log(`Bypassed ${details.tabId} ${url}`) - if (!BYPASSTABs.includes(details.tabId)) BYPASSTABs.push(details.tabId) - return null - } - console.info("Redirecting", url.href, "=>", newUrl) - return { redirectUrl: newUrl } - } - return null - }, - { urls: [""] }, - ["blocking"] -) - -browser.tabs.onRemoved.addListener(tabId => { - const i = BYPASSTABs.indexOf(tabId) - if (i > -1) { - BYPASSTABs.splice(i, 1) - console.log("Removed BYPASSTABs", tabId) - } -}) - -/* -browser.webRequest.onHeadersReceived.addListener( - e => { - let response = youtubeHelper.removeXFrameOptions(e) - if (!response) response = twitterHelper.removeXFrameOptions(e) - return response - }, - { urls: [""] }, - ["blocking", "responseHeaders"] -) -*/ - -async function redirectOfflineInstance(url, tabId) { - let newUrl = await servicesHelper.switchInstance(url, true) - - if (newUrl) { - if (counter >= 5) { - browser.tabs.update(tabId, { - url: `/pages/errors/instance_offline.html?url=${encodeURIComponent(newUrl)}`, - }) - counter = 0 - } else { - browser.tabs.update(tabId, { url: newUrl }) - counter++ - } - } -} -let counter = 0 - -function isAutoRedirect() { - return new Promise(resolve => browser.storage.local.get("options", r => resolve(r.options.autoRedirect == true))) -} - -browser.webRequest.onResponseStarted.addListener( - async details => { - if (!(await isAutoRedirect())) return null - if (details.type == "main_frame" && details.statusCode >= 500) redirectOfflineInstance(new URL(details.url), details.tabId) - }, - { urls: [""] } -) - -browser.webRequest.onErrorOccurred.addListener( - async details => { - if (!(await isAutoRedirect())) return - if (details.type == "main_frame") redirectOfflineInstance(new URL(details.url), details.tabId) - }, - { urls: [""] } -) - -browser.commands.onCommand.addListener(command => { - if (command === "switchInstance") utils.switchInstance() - else if (command == "copyRaw") utils.copyRaw() - else if (command == "unify") utils.unify() -}) - -browser.contextMenus.create({ - id: "settings", - title: browser.i18n.getMessage("Settings"), - contexts: ["browser_action"], -}) - -browser.contextMenus.create({ - id: "switchInstance", - title: browser.i18n.getMessage("switchInstance"), - contexts: ["browser_action"], -}) - -browser.contextMenus.create({ - id: "copyRaw", - title: browser.i18n.getMessage("copyRaw"), - contexts: ["browser_action"], -}) - -browser.contextMenus.create({ - id: "unify", - title: browser.i18n.getMessage("unifySettings"), - contexts: ["browser_action"], -}) - -browser.contextMenus.onClicked.addListener(info => { - if (info.menuItemId == "switchInstance") utils.switchInstance() - else if (info.menuItemId == "settings") browser.runtime.openOptionsPage() - else if (info.menuItemId == "copyRaw") utils.copyRaw() - else if (info.menuItemId == "unify") utils.unify() -}) - -browser.runtime.onMessage.addListener((message, sender, sendResponse) => { - if (message.function === "unify") utils.unify(false).then(r => sendResponse({ response: r })) - return true -}) ->>>>>>> optimizations -- cgit 1.4.1 From b9d25cd73733d7421c3464dbcb4a87c64ce42b4d Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Sun, 9 Oct 2022 09:34:59 +0200 Subject: Changed matrix url from Space to just the room --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index 8c5d6080..483852ba 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ A web extension that redirects YouTube, Twitter, Instagram... requests to alternative privacy friendly frontends and backends. -[![Matrix Badge](https://img.shields.io/matrix/libredirect:matrix.org?label=matrix%20chat)](https://matrix.to/#/#libredirect-space:matrix.org) +[![Matrix Badge](https://img.shields.io/matrix/libredirect:matrix.org?label=matrix%20chat)](https://matrix.to/#/#libredirect:matrix.org) [![Firefox users Badge](https://img.shields.io/amo/users/libredirect?label=Firefox%20users)](https://addons.mozilla.org/firefox/addon/libredirect/) [![LibrePay Badge](https://img.shields.io/liberapay/gives/libredirect?label=Liberapay)](https://liberapay.com/LibRedirect) -- cgit 1.4.1 From 394ef5d3bbe21d28164d8a4ae659c286f737cc58 Mon Sep 17 00:00:00 2001 From: EdwardLangdon Date: Sun, 9 Oct 2022 07:36:44 +0000 Subject: Added OpenCollective to Readme --- .gitignore | 1 + README.md | 3 ++- img/Open-Collective.png | Bin 0 -> 37041 bytes 3 files changed, 3 insertions(+), 1 deletion(-) create mode 100644 img/Open-Collective.png (limited to 'README.md') diff --git a/.gitignore b/.gitignore index f6fc62d4..09e0ce26 100644 --- a/.gitignore +++ b/.gitignore @@ -3,3 +3,4 @@ web-ext-artifacts/ nod node_modules package-lock.json +.vscode \ No newline at end of file diff --git a/README.md b/README.md index 8c5d6080..b0a3c9fd 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,8 @@ Send Files => [Send](https://gitlab.com/timvisee/send) [![Liberapay](./img/liberapay.svg)](https://liberapay.com/LibRedirect)  [![Patreon](./img/patreon.svg)](https://patreon.com/LibRedirect)  -[![Buy me a coffee](./img/bmc.svg)](https://www.buymeacoffee.com/libredirect) +[![Buy me a coffee](./img/bmc.svg)](https://www.buymeacoffee.com/libredirect)  +
BTC: bc1qrhue0frps6p2vkg978u9ayethnwprtmfug827q\ BCH: qqz5vfnrngk0tjy73q2688qzw4wnllnuzqfndflhl8\ diff --git a/img/Open-Collective.png b/img/Open-Collective.png new file mode 100644 index 00000000..d667babc Binary files /dev/null and b/img/Open-Collective.png differ -- cgit 1.4.1 From ec2a711dee1f25931713705548c5432fd1ab2196 Mon Sep 17 00:00:00 2001 From: EdwardLangdon Date: Sun, 9 Oct 2022 07:45:47 +0000 Subject: Fixed minor markdown error in Previous Commit --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index a42ad18c..16e04a2a 100644 --- a/README.md +++ b/README.md @@ -43,7 +43,7 @@ Send Files => [Send](https://gitlab.com/timvisee/send) [![Liberapay](./img/liberapay.svg)](https://liberapay.com/LibRedirect)  [![Patreon](./img/patreon.svg)](https://patreon.com/LibRedirect)  [![Buy me a coffee](./img/bmc.svg)](https://www.buymeacoffee.com/libredirect)  - + BTC: bc1qrhue0frps6p2vkg978u9ayethnwprtmfug827q\ BCH: qqz5vfnrngk0tjy73q2688qzw4wnllnuzqfndflhl8\ -- cgit 1.4.1 From 9a87e7acb6bd7d3072c6ac1b1525c8e639602cd4 Mon Sep 17 00:00:00 2001 From: EdwardLangdon Date: Sun, 9 Oct 2022 07:53:06 +0000 Subject: Changed order of Mirror repos --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'README.md') diff --git a/README.md b/README.md index 16e04a2a..cc6ba939 100644 --- a/README.md +++ b/README.md @@ -52,8 +52,9 @@ XMR: 4AM5CVfaGsnEXQQjZSzJvaWufe7pT86ubcZPr83fCjb2Hn3iwcForTWFy2Z3ugXcufUwHaGcucf ## Mirror Repos -[![GitHub](https://raw.githubusercontent.com/ManeraKai/manerakai/main/icons/github.svg)](https://github.com/libredirect/libredirect/)   [![Codeberg](https://raw.githubusercontent.com/ManeraKai/manerakai/main/icons/codeberg.svg)](https://codeberg.org/LibRedirect/libredirect)   +[![GitHub](https://raw.githubusercontent.com/ManeraKai/manerakai/main/icons/github.svg)](https://github.com/libredirect/libredirect/)   + ## Translate -- cgit 1.4.1