From 4c69fa7e292a3896ef5f4daf1e6dea3c9bd0b446 Mon Sep 17 00:00:00 2001 From: BobIsMyManager Date: Mon, 1 Aug 2022 13:31:16 +0100 Subject: Latency threshold, LBRY/Odysee -> LBRY Closes https://github.com/libredirect/libredirect/pull/405 --- src/pages/popup/popup.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/pages/popup/popup.html') diff --git a/src/pages/popup/popup.html b/src/pages/popup/popup.html index 7493ecbe..25f70f48 100644 --- a/src/pages/popup/popup.html +++ b/src/pages/popup/popup.html @@ -28,7 +28,7 @@

TikTok

-
+ @@ -122,7 +122,7 @@

TikTok

-
+ -- cgit 1.4.1 From 320d0175a8e1223618eb3b8d740b420ef674fc8d Mon Sep 17 00:00:00 2001 From: Hygna Date: Thu, 22 Sep 2022 19:58:07 +0100 Subject: Completed Migration to ejs --- package.json | 2 +- src/assets/images/sendTargets-icon.svg | 52 +---- src/assets/javascripts/services.js | 8 +- src/config/config.json | 67 ++++-- src/instances/get_instances.py | 2 +- src/pages/options/index.html | 109 ++++++--- src/pages/options/widgets/services.js | 2 +- src/pages/popup/popup.ejs | 49 ++++ src/pages/popup/popup.html | 396 ++++++++++++++++++--------------- src/pages/popup/popup.pug | 155 ------------- src/pages/widgets/head.pug | 5 - src/pages/widgets/icons.pug | 46 ---- src/pages/widgets/instances.pug | 15 -- src/pages/widgets/latency.pug | 14 -- src/pages/widgets/links.ejs | 12 +- src/pages/widgets/links.pug | 83 ------- src/pages/widgets/switches.ejs | 11 + 17 files changed, 422 insertions(+), 606 deletions(-) create mode 100644 src/pages/popup/popup.ejs delete mode 100644 src/pages/popup/popup.pug delete mode 100644 src/pages/widgets/head.pug delete mode 100644 src/pages/widgets/icons.pug delete mode 100644 src/pages/widgets/instances.pug delete mode 100644 src/pages/widgets/latency.pug delete mode 100644 src/pages/widgets/links.pug create mode 100644 src/pages/widgets/switches.ejs (limited to 'src/pages/popup/popup.html') diff --git a/package.json b/package.json index ee0d9089..76f57474 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "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" + "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" }, "repository": { "type": "git", diff --git a/src/assets/images/sendTargets-icon.svg b/src/assets/images/sendTargets-icon.svg index 2ed80a06..5557664e 100644 --- a/src/assets/images/sendTargets-icon.svg +++ b/src/assets/images/sendTargets-icon.svg @@ -1,51 +1,3 @@ - - - - - - - - + + diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 79444442..f4c30873 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -68,7 +68,7 @@ function redirect(url, type, initiator) { let redirectType if (url.pathname == "/") return for (const service in config.services) { - if (!options[service].enabled && !disableOverride) continue + if (!options[service].enabled) continue let targets = service.targets if (targets == "datajson") { browser.storage.local.get(`${service}Targets`, (targets = r[service + "Targets"])) @@ -385,12 +385,12 @@ function initDefaults() { .then(response => response.text()) .then(async data => { let dataJson = JSON.parse(data) - redirects = dataJson.slice() + redirects = JSON.parse(data) browser.storage.local.get(["cloudflareBlackList", "authenticateBlackList", "offlineBlackList"], async r => { for (const service in config.services) { if (config.services[service].targets == "datajson") { browser.storage.local.set({ [service + "Targets"]: [...dataJson[service]] }) - delete redirects[service] + delete dataJson[service] } for (const defaultOption in config.services[service].options) { browser.storage.local.set({ [service + utils.camelCase(defaultOption)]: config.services[service].options[defaultOption] }) @@ -422,7 +422,7 @@ function initDefaults() { } }) browser.storage.local.set({ - redirects, + redirects: dataJson, }) ;() => resolve() }) diff --git a/src/config/config.json b/src/config/config.json index ac393f18..1c8f5f9f 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -102,7 +102,8 @@ "embedFrontend": "invidious" }, "imageType": "png", - "embeddable": true + "embeddable": true, + "url": "https://youtube.com" }, "youtubeMusic": { "frontends": { @@ -130,7 +131,8 @@ "frontend": "beatbump" }, "imageType": "png", - "embeddable": false + "embeddable": false, + "url": "https://music.youtube.com" }, "twitter": { "frontends": { @@ -169,7 +171,8 @@ "redirectType": "both" }, "imageType": "png", - "embeddable": true + "embeddable": true, + "url": "https://twitter.com" }, "instagram": { "frontends": { @@ -187,7 +190,8 @@ "name": "Instagram", "options": { "enabled": true }, "imageType": "png", - "embeddable": false + "embeddable": false, + "url": "https://instagram.com" }, "tiktok": { "frontends": { @@ -203,7 +207,8 @@ "name": "TikTok", "options": { "enabled": true }, "imageType": "png", - "embeddable": false + "embeddable": false, + "url": "https://tiktok.com" }, "reddit": { "frontends": { @@ -242,7 +247,8 @@ "frontend": "libreddit" }, "imageType": "png", - "embeddable": false + "embeddable": false, + "url": "https://reddit.com" }, "imgur": { "frontends": { @@ -256,7 +262,8 @@ "name": "Imgur", "options": { "enabled": true }, "imageType": "png", - "embeddable": false + "embeddable": false, + "url": "https://imgur.com" }, "wikipedia": { "frontends": { @@ -272,7 +279,8 @@ "name": "Wikipedia", "options": { "enabled": false }, "imageType": "svg", - "embeddable": false + "embeddable": false, + "url": "https://wikipedia.com" }, "medium": { "frontends": { @@ -304,8 +312,9 @@ ], "name": "Medium", "options": { "enabled": true }, - "imageType": "svg", - "embeddable": false + "imageType": "svgMono", + "embeddable": false, + "url": "https://medium.com" }, "quora": { "frontends": { @@ -321,7 +330,8 @@ "name": "Quora", "options": { "enabled": true }, "imageType": "png", - "embeddable": false + "embeddable": false, + "url": "https://quora.com" }, "imdb": { "frontends": { @@ -337,7 +347,8 @@ "name": "IMDb", "options": { "enabled": false }, "imageType": "svg", - "embeddable": false + "embeddable": false, + "url": "https://imdb.com" }, "reuters": { "frontends": { @@ -351,7 +362,8 @@ "name": "Reuters", "options": { "enabled": false }, "imageType": "svg", - "embeddable": false + "embeddable": false, + "url": "https://reuters.com" }, "peertube": { "frontends": { @@ -365,7 +377,8 @@ "name": "PeerTube", "options": { "enabled": false }, "imageType": "svg", - "embeddable": false + "embeddable": false, + "url": "https://search.joinpeertube.org" }, "lbry": { "frontends": { @@ -389,10 +402,12 @@ "options": { "enabled": false, "frontend": "librarian", - "redirectType": "both" + "redirectType": "both", + "embedFrontend": "librarian" }, "imageType": "png", - "embeddable": true + "embeddable": true, + "url": "https://odysee.com" }, "search": { "frontends": { @@ -467,8 +482,9 @@ "enabled": true, "frontend": "searxng" }, - "imageType": "svg", - "embeddable": false + "imageType": "svgMono", + "embeddable": false, + "url": "https://search.libredirect.invalid" }, "translate": { "frontends": { @@ -493,8 +509,9 @@ "enabled": true, "frontend": "simplyTranslate" }, - "imageType": "svg", - "embeddable": false + "imageType": "svgMono", + "embeddable": false, + "url": "https://translate.google.com" }, "maps": { "frontends": { @@ -514,8 +531,9 @@ "enabled": true, "frontend": "osm" }, - "imageType": "svg", - "embeddable": false + "imageType": "svgMono", + "embeddable": false, + "url": "https://maps.google.com" }, "sendTargets": { "frontends": { @@ -528,8 +546,9 @@ "targets": ["^https?:\\/{2}send\\.libredirect\\.invalid\\/$", "^https?:\\/{2}send\\.firefox\\.com\\/$", "^https?:\\/{2}sendfiles\\.online\\/$"], "name": "Send Files", "options": { "enabled": true }, - "imageType": "svg", - "embeddable": false + "imageType": "svgMono", + "embeddable": false, + "url": "https://send.libredirect.invalid" } } } diff --git a/src/instances/get_instances.py b/src/instances/get_instances.py index 2547917a..85bdf1cf 100644 --- a/src/instances/get_instances.py +++ b/src/instances/get_instances.py @@ -446,7 +446,7 @@ def peertube(): 'https://instances.joinpeertube.org/api/v1/instances?start=0&count=1045&sort=-createdAt') rJson = json.loads(r.text) - myList = [] + myList = ['https://search.joinpeertube.org'] for k in rJson['data']: myList.append('https://'+k['host']) diff --git a/src/pages/options/index.html b/src/pages/options/index.html index e1163e99..a23ff247 100644 --- a/src/pages/options/index.html +++ b/src/pages/options/index.html @@ -10,26 +10,85 @@
@@ -169,7 +228,7 @@
-
+
medium
@@ -205,25 +264,25 @@
-
+
search
-
+
translate
-
+
maps
-
+
sendTargets
diff --git a/src/pages/options/widgets/services.js b/src/pages/options/widgets/services.js index 69840de4..b595943e 100644 --- a/src/pages/options/widgets/services.js +++ b/src/pages/options/widgets/services.js @@ -53,7 +53,7 @@ function changeFrontendsSettings(service) { } } } - } else if (Object.keys(config.services[service].frontends) > 1) divs[service].embedFrontend.disabled = true + } else if (Object.keys(config.services[service].frontends).length > 1) divs[service].embedFrontend.disabled = true } } diff --git a/src/pages/popup/popup.ejs b/src/pages/popup/popup.ejs new file mode 100644 index 00000000..efb73e5c --- /dev/null +++ b/src/pages/popup/popup.ejs @@ -0,0 +1,49 @@ + + + + + + + + + +
+ <%- include('src/pages/widgets/switches', {config: config}) -%> +
+
+
+
+
+ <%- include('src/pages/widgets/switches', {config: config}) -%> +
+
+ + + + + +
+ + + + diff --git a/src/pages/popup/popup.html b/src/pages/popup/popup.html index 25f70f48..e21a63a0 100644 --- a/src/pages/popup/popup.html +++ b/src/pages/popup/popup.html @@ -8,189 +8,227 @@
@@ -222,4 +260,4 @@ - \ No newline at end of file + diff --git a/src/pages/popup/popup.pug b/src/pages/popup/popup.pug deleted file mode 100644 index 7da687cc..00000000 --- a/src/pages/popup/popup.pug +++ /dev/null @@ -1,155 +0,0 @@ -include ../widgets/icons.pug - -mixin services - .youtube.some-block - a.title(href="https://youtube.com") - img(src="../../assets/images/youtube-icon.png") - h4(data-localise="__MSG_youtube__") YouTube - input.disable-youtube(type="checkbox") - - .youtubeMusic.some-block - a.title(href="https://music.youtube.com") - img(src="../../assets/images/youtube-music-icon.png") - h4(data-localise="__MSG_ytmusic__") YT Music - input.disable-youtubeMusic(type="checkbox") - - .twitter.some-block - a.title(href="https://twitter.com") - img(src="../../assets/images/twitter-icon.png") - h4(data-localise="__MSG_twitter__") Twitter - input.disable-nitter(type="checkbox") - - .instagram.some-block - a.title(href="https://instagram.com") - img(src="../../assets/images/instagram-icon.png") - h4(data-localise="__MSG_instagram__") Instagram - input.disable-bibliogram(type="checkbox") - - .tiktok.some-block - a.title(href="https://tiktok.com") - img(src="../../assets/images/tiktok-icon.png") - h4(data-localise="__MSG_tiktok__") TikTok - input.disable-tiktok(type="checkbox") - - .imgur.some-block - a.title(href="https://imgur.com") - img(src="../../assets/images/imgur.png") - h4(data-localise="__MSG_imgur__") Imgur - input.disable-imgur(type="checkbox") - - .reddit.some-block - a.title(href="https://reddit.com") - img(src="../../assets/images/reddit-icon.png") - h4(data-localise="__MSG_reddit__") Reddit - input.disable-reddit(type="checkbox") - - .wikipedia.some-block - a.title(href="https://wikipedia.com") - img(src="../../assets/images/wikipedia-icon.svg") - h4(data-localise="__MSG_wikipedia__") Wikipedia - input.disable-wikipedia(type="checkbox") - - .medium.some-block - a.title(href="https://medium.com") - +medium - h4(data-localise="__MSG_medium__") Medium - input.disable-medium(type="checkbox") - - .quora.some-block - a.title(href="https://quora.com") - img(src="../../assets/images/quora.png") - h4(data-localise="__MSG_quora__") Quora - input.disable-quora(type="checkbox") - - .imdb.some-block - a.title(href="https://imdb.com") - img(src="../../assets/images/imdb.svg") - h4(data-localise="__MSG_imdb__") IMDb - input.disable-imdb(type="checkbox") - - .reuters.some-block - a.title(href="https://reuters.com") - img(src="../../assets/images/reuters.svg") - h4(data-localise="__MSG_reuters__") Reuters - input.disable-reuters(type="checkbox") - - .peertube.some-block - a.title(href="https://search.joinpeertube.org") - img(src="../../assets/images/peertube-icon.svg") - h4(data-localise="__MSG_peertube__") PeerTube - input.disable-peertube(type="checkbox") - - .lbry.some-block - a.title(href="https://odysee.com/") - img(src="../../assets/images/lbry-icon.png") - h4(data-localise="__MSG_lbry__") LBRY - input.disable-lbry(type="checkbox") - - .search.some-block - a.title(href="https://search.libredirect.invalid") - +search - h4(data-localise="__MSG_search__") Search - input.disable-search(type="checkbox") - - .translate.some-block - a.title(href="https://translate.google.com") - +translate - h4(data-localise="__MSG_translate__") Translate - input.disable-translate(type="checkbox") - - .maps.some-block - a.title(href="https://www.openstreetmap.org") - +maps - h4(data-localise="__MSG_maps__") Maps - input.disable-osm(type="checkbox") - - .sendTargets.some-block - a.title(href="https://send.libredirect.invalid") - +send - h4(data-localise="__MSG_sendFiles__") Send Files - input.disable-sendTargets(type="checkbox") - -doctype html -html(lang="en") - head - meta(charset="utf-8") - meta(name="viewport" content="width=device-width, initial-scale=1") - link(href="../stylesheets/styles.css" rel="stylesheet") - link(href="./style.css" rel="stylesheet") - body(dir="auto") - .current_site - +services - #current_site_divider - hr - .all_sites - +services - hr - #change_instance_div.some-block - a#change_instance.title.button.prevent - h4(data-localise="__MSG_switchInstance__") Change Instance - +change_instance - - #copy_raw_div.some-block(title="Copy the original redirected link") - a#copy_raw.title.button.prevent - h4(data-localise="__MSG_copyRaw__") Copy Raw - +copy_raw - - #unify_div.some-block(title="Unify cookies across all selected instances") - a#unify.title.button.prevent - h4(data-localise="__MSG_unifySettings__") Unify Settings - +unify - - .some-block - a#more-options.title.button.prevent - h4(data-localise="__MSG_settings__") Settings - +settings - - .some-block - a#about.title.button(href="/pages/options/index.html#about") - h4(data-localise="__MSG_about__") About - +about - - .space - - script(type="module" src="../options/init.js") - script(type="module" src="./popup.js") diff --git a/src/pages/widgets/head.pug b/src/pages/widgets/head.pug deleted file mode 100644 index 53de42d3..00000000 --- a/src/pages/widgets/head.pug +++ /dev/null @@ -1,5 +0,0 @@ -head - meta(charset='utf-8') - meta(name="viewport" content="width=device-width, initial-scale=1") - link(rel="icon" type="image/x-icon" href="../../../assets/images/libredirect.svg") - link(href="../../stylesheets/styles.css" rel="stylesheet") \ No newline at end of file diff --git a/src/pages/widgets/icons.pug b/src/pages/widgets/icons.pug deleted file mode 100644 index cc77ad16..00000000 --- a/src/pages/widgets/icons.pug +++ /dev/null @@ -1,46 +0,0 @@ -mixin medium - svg(xmlns="http://www.w3.org/2000/svg" viewBox="0 0 1770 1000" fill="currentColor") - circle(cx="500" cy="500" r="500") - ellipse(ry="475" rx="250" cy="501" cx="1296") - ellipse(cx="1682" cy="502" rx="88" ry="424") - -mixin search - svg(xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor") - path(d="M15.5 14h-.79l-.28-.27C15.41 12.59 16 11.11 16 9.5 16 5.91 13.09 3 9.5 3S3 5.91 3 9.5 5.91 16 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z") - -mixin translate - svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") - path(d="M12.87 15.07l-2.54-2.51.03-.03c1.74-1.94 2.98-4.17 3.71-6.53H17V4h-7V2H8v2H1v1.99h11.17C11.5 7.92 10.44 9.75 9 11.35 8.07 10.32 7.3 9.19 6.69 8h-2c.73 1.63 1.73 3.17 2.98 4.56l-5.09 5.02L4 19l5-5 3.11 3.11.76-2.04zM18.5 10h-2L12 22h2l1.12-3h4.75L21 22h2l-4.5-12zm-2.62 7l1.62-4.33L19.12 17h-3.24z") - -mixin maps - svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") - path( d="M20.5 3l-.16.03L15 5.1 9 3 3.36 4.9c-.21.07-.36.25-.36.48V20.5c0 .28.22.5.5.5l.16-.03L9 18.9l6 2.1 5.64-1.9c.21-.07.36-.25.36-.48V3.5c0-.28-.22-.5-.5-.5zM10 5.47l4 1.4v11.66l-4-1.4V5.47zm-5 .99l3-1.01v11.7l-3 1.16V6.46zm14 11.08l-3 1.01V6.86l3-1.16v11.84z") - -mixin send - svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") - path(d="M19.35 10.04C18.67 6.59 15.64 4 12 4 9.11 4 6.6 5.64 5.35 8.04 2.34 8.36 0 10.91 0 14c0 3.31 2.69 6 6 6h13c2.76 0 5-2.24 5-5 0-2.64-2.05-4.78-4.65-4.96zM14 13v4h-4v-4H7l5-5 5 5h-3z") - -mixin change_instance - svg(xmlns="http://www.w3.org/2000/svg" height="26px" viewBox="0 0 24 24" width="26px" fill="currentColor") - path(d="M12 4V1L8 5l4 4V6c3.31 0 6 2.69 6 6 0 1.01-.25 1.97-.7 2.8l1.46 1.46C19.54 15.03 20 13.57 20 12c0-4.42-3.58-8-8-8zm0 14c-3.31 0-6-2.69-6-6 0-1.01.25-1.97.7-2.8L5.24 7.74C4.46 8.97 4 10.43 4 12c0 4.42 3.58 8 8 8v3l4-4-4-4v3z") - -mixin settings - svg(xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="26px" viewBox="0 0 24 24" - width="26px" fill="currentColor") - path(d="M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.8,11.69,4.8,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z") - -mixin copy_raw - svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") - path(d="M16 1H4c-1.1 0-2 .9-2 2v14h2V3h12V1zm3 4H8c-1.1 0-2 .9-2 2v14c0 1.1.9 2 2 2h11c1.1 0 2-.9 2-2V7c0-1.1-.9-2-2-2zm0 16H8V7h11v14z") - -mixin general - svg(xmlns="http://www.w3.org/2000/svg" enable-background="new 0 0 24 24" height="26px" viewBox="0 0 24 24" width="26px" fill="currentColor") - path(d="M19.14,12.94c0.04-0.3,0.06-0.61,0.06-0.94c0-0.32-0.02-0.64-0.07-0.94l2.03-1.58c0.18-0.14,0.23-0.41,0.12-0.61 l-1.92-3.32c-0.12-0.22-0.37-0.29-0.59-0.22l-2.39,0.96c-0.5-0.38-1.03-0.7-1.62-0.94L14.4,2.81c-0.04-0.24-0.24-0.41-0.48-0.41 h-3.84c-0.24,0-0.43,0.17-0.47,0.41L9.25,5.35C8.66,5.59,8.12,5.92,7.63,6.29L5.24,5.33c-0.22-0.08-0.47,0-0.59,0.22L2.74,8.87 C2.62,9.08,2.66,9.34,2.86,9.48l2.03,1.58C4.84,11.36,4.8,11.69,4.8,12s0.02,0.64,0.07,0.94l-2.03,1.58 c-0.18,0.14-0.23,0.41-0.12,0.61l1.92,3.32c0.12,0.22,0.37,0.29,0.59,0.22l2.39-0.96c0.5,0.38,1.03,0.7,1.62,0.94l0.36,2.54 c0.05,0.24,0.24,0.41,0.48,0.41h3.84c0.24,0,0.44-0.17,0.47-0.41l0.36-2.54c0.59-0.24,1.13-0.56,1.62-0.94l2.39,0.96 c0.22,0.08,0.47,0,0.59-0.22l1.92-3.32c0.12-0.22,0.07-0.47-0.12-0.61L19.14,12.94z M12,15.6c-1.98,0-3.6-1.62-3.6-3.6 s1.62-3.6,3.6-3.6s3.6,1.62,3.6,3.6S13.98,15.6,12,15.6z") - -mixin unify - svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") - path(d="M3.9 12c0-1.71 1.39-3.1 3.1-3.1h4V7H7c-2.76 0-5 2.24-5 5s2.24 5 5 5h4v-1.9H7c-1.71 0-3.1-1.39-3.1-3.1zM8 13h8v-2H8v2zm9-6h-4v1.9h4c1.71 0 3.1 1.39 3.1 3.1s-1.39 3.1-3.1 3.1h-4V17h4c2.76 0 5-2.24 5-5s-2.24-5-5-5z") - -mixin about - svg( xmlns="http://www.w3.org/2000/svg" height="24" width="24" fill="currentColor") - path( d="M11 17h2v-6h-2Zm1-8q.425 0 .713-.288Q13 8.425 13 8t-.287-.713Q12.425 7 12 7t-.712.287Q11 7.575 11 8t.288.712Q11.575 9 12 9Zm0 13q-2.075 0-3.9-.788-1.825-.787-3.175-2.137-1.35-1.35-2.137-3.175Q2 14.075 2 12t.788-3.9q.787-1.825 2.137-3.175 1.35-1.35 3.175-2.138Q9.925 2 12 2t3.9.787q1.825.788 3.175 2.138 1.35 1.35 2.137 3.175Q22 9.925 22 12t-.788 3.9q-.787 1.825-2.137 3.175-1.35 1.35-3.175 2.137Q14.075 22 12 22Zm0-2q3.35 0 5.675-2.325Q20 15.35 20 12q0-3.35-2.325-5.675Q15.35 4 12 4 8.65 4 6.325 6.325 4 8.65 4 12q0 3a.35 2.325 5.675Q8.65 20 12 20Zm0-8Z") \ No newline at end of file diff --git a/src/pages/widgets/instances.pug b/src/pages/widgets/instances.pug deleted file mode 100644 index 950bd46b..00000000 --- a/src/pages/widgets/instances.pug +++ /dev/null @@ -1,15 +0,0 @@ -mixin instances(myPlaceholder) - .some-block.option-block - h4(data-localise="__MSG_defaultInstances__") Default Instances - - .checklist - hr - .some-block.option-block - h4(data-localise="__MSG_customInstances__") Custom Instances - form.custom-instance-form - .some-block.option-block - input.custom-instance(placeholder=myPlaceholder type="url") - button.add.add-instance(type="submit") - svg(xmlns="https://www.w3.org/2000/svg" height="20px" viewBox="0 0 24 24" width="20px" fill="currentColor") - path(d="M19 13h-6v6h-2v-6H5v-2h6V5h2v6h6v2z") - .checklist.custom-checklist \ No newline at end of file diff --git a/src/pages/widgets/latency.pug b/src/pages/widgets/latency.pug deleted file mode 100644 index e5bf53b2..00000000 --- a/src/pages/widgets/latency.pug +++ /dev/null @@ -1,14 +0,0 @@ -mixin latency(service) - - var latencyVal - if (service) - - latencyVal = `latency-${service}` - else - - latencyVal = `latency` - - .buttons.buttons-inline - label.button.button-inline(id=`${latencyVal}-label` for=latencyVal) - svg(xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 0 24 24" width="24px" fill="currentColor") - path(d="M19 19H5V5h7V3H5c-1.11 0-2 .9-2 2v14c0 1.1.89 2 2 2h14c1.1 0 2-.9 2-2v-7h-2v7zM14 3v2h3.59l-9.83 9.83 1.41 1.41L19 6.41V10h2V3h-7z") - |  - x(data-localise="__MSG_testInstancesLatency__") Test Instances Latency - input.button.button-inline(id=latencyVal style="display:none;") \ No newline at end of file diff --git a/src/pages/widgets/links.ejs b/src/pages/widgets/links.ejs index c28d3668..86b9f260 100644 --- a/src/pages/widgets/links.ejs +++ b/src/pages/widgets/links.ejs @@ -1,7 +1,13 @@ diff --git a/src/pages/widgets/links.pug b/src/pages/widgets/links.pug deleted file mode 100644 index c7f8e0a6..00000000 --- a/src/pages/widgets/links.pug +++ /dev/null @@ -1,83 +0,0 @@ -include ./icons.pug - -mixin links(service) - section#links.links - .title - +general - a(href="#general" data-localise="__MSG_general__") General - - .title - img(src="../../../assets/images/youtube-icon.png") - a(href="#youtube" data-localise="__MSG_youtube__") YouTube - - .title - img(src="../../../assets/images/youtube-music-icon.png") - a(href="#youtubeMusic" data-localise="__MSG_ytmusic__") YT Music - - .title - img(src="../../../assets/images/twitter-icon.png") - a(href="#twitter" data-localise="__MSG_twitter__") Twitter - - .title - img(src="../../../assets/images/instagram-icon.png") - a(href="#instagram" data-localise="__MSG_instagram__") Instagram - - .title - img(src="../../../assets/images/tiktok-icon.png") - a(href="#tiktok" data-localise="__MSG_tiktok__") TikTok - - .title - img(src="../../../assets/images/reddit-icon.png") - a(href="#reddit" data-localise="__MSG_reddit__") Reddit - - .title - img(src="../../../assets/images/imgur.png") - a(href="#imgur" data-localise="__MSG_imgur__") Imgur - - .title - img(src="../../../assets/images/wikipedia-icon.svg") - a(href="#wikipedia" data-localise="__MSG_wikipedia__") Wikipedia - - .title - +medium - a(href="#medium" data-localise="__MSG_medium__") Medium - - .title - img(src="../../../assets/images/quora.png") - a(href="#quora" data-localise="__MSG_quora__") Quora - - .title - img(src="../../../assets/images/imdb.svg") - a(href="#imdb" data-localise="__MSG_imdb__") IMDb - - .title - img(src="../../../assets/images/reuters.svg") - a(href="#reuters" data-localise="__MSG_reuters__") Reuters - - .title - img(src="../../../assets/images/peertube-icon.svg") - a(href="#peertube" data-localise="__MSG_peertube__") PeerTube - - .title - img(src="../../../assets/images/lbry-icon.png") - a(href="#lbry" data-localise="__MSG_lbry__") LBRY - - .title - +search - a(href="#search" data-localise="__MSG_search__") Search - - .title - +translate - a(href="#translate" data-localise="__MSG_translate__") Translate - - .title - +maps - a(href="#maps" data-localise="__MSG_maps__") Maps - - .title - +send - a(href="#sendTargets" data-localise="__MSG_sendFiles__") Send Files - - .title - +about - a(href="#about" data-localise="__MSG_about") About diff --git a/src/pages/widgets/switches.ejs b/src/pages/widgets/switches.ejs new file mode 100644 index 00000000..45bcd790 --- /dev/null +++ b/src/pages/widgets/switches.ejs @@ -0,0 +1,11 @@ +<% for (const service in config.services) { -%> + +<% } %> -- 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 'src/pages/popup/popup.html') 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 18facf37a2f058b1314f5fd3a1f9d36c70ba27f5 Mon Sep 17 00:00:00 2001 From: Hygna Date: Fri, 30 Sep 2022 14:54:56 +0100 Subject: Squashed a few bugs --- src/assets/images/sendTargets-icon.svg | 3 - src/assets/javascripts/services.js | 36 +++++++--- src/assets/javascripts/utils.js | 124 ++++++++++++++++----------------- src/config/config.json | 19 ++--- src/pages/background/background.js | 30 ++++---- src/pages/options/index.html | 14 ++-- src/pages/options/widgets/general.js | 2 +- src/pages/options/widgets/services.js | 2 +- src/pages/popup/popup.html | 20 +++--- 9 files changed, 131 insertions(+), 119 deletions(-) delete mode 100644 src/assets/images/sendTargets-icon.svg (limited to 'src/pages/popup/popup.html') diff --git a/src/assets/images/sendTargets-icon.svg b/src/assets/images/sendTargets-icon.svg deleted file mode 100644 index 5557664e..00000000 --- a/src/assets/images/sendTargets-icon.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 49af6d1f..404962ee 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -391,7 +391,7 @@ function redirect(url, type, initiator) { } } -function initDefaults() { +async function initDefaults() { return new Promise(async resolve => { fetch("/instances/data.json") .then(response => response.text()) @@ -400,13 +400,12 @@ function initDefaults() { let redirects = JSON.parse(data) let options = r.options let targets = {} - // let latency = {} + const localstorage = {} + const latency = {} for (const service in config.services) { options[service] = {} - // latency[service] = {} if (config.services[service].targets == "datajson") { targets[service] = redirects[service] - //delete dataJson[service] } for (const defaultOption in config.services[service].options) { options[service][defaultOption] = config.services[service].options[defaultOption] @@ -416,11 +415,11 @@ function initDefaults() { options[frontend] = {} for (const network in config.networks) { options[frontend][network] = {} - options[frontend][network].enabled = redirects[frontend][network] + options[frontend][network].enabled = JSON.parse(data)[frontend][network] options[frontend][network].custom = [] } for (const blacklist in r.blacklists) { - for (const instance of blacklist) { + for (const instance of r.blacklists[blacklist]) { let i = options[frontend].clearnet.enabled.indexOf(instance) if (i > -1) options[frontend].clearnet.enabled.splice(i, 1) } @@ -428,7 +427,7 @@ function initDefaults() { } } } - browser.storage.local.set({ redirects, options, targets /*, latency*/ }) + browser.storage.local.set({ redirects, options, targets, latency, localstorage }) resolve() }) }) @@ -449,7 +448,8 @@ function computeService(url, returnFrontend) { } } } - return null + if (returnFrontend) return [null, null] + else return null } function switchInstance(url) { @@ -515,7 +515,7 @@ function reverse(url) { }) } -function unifyPreferences(url) { +function unifyPreferences(url, tabId) { return new Promise(async resolve => { // await init() // await getConfig() @@ -539,7 +539,23 @@ function unifyPreferences(url) { await utils.copyCookie(currentFrontend, url, instancesList, cookie) } } - if ("localStorage" in frontend.preferences) { + if ("localstorage" in frontend.preferences) { + browser.tabs.executeScript(tabId, { + code: "const frontend = " + frontend, + code: "const items = " + config.services[currentService].frontends[currentFrontend].preferences.localStorage, + //file: "/assets/javascripts/get-localstorage.js", + runAt: "document_start", + }) + + for (const instance of instancesList) + browser.tabs.create({ url: instance }, tab => + browser.tabs.executeScript(tab.id, { + code: "const frontend = " + frontend, + code: "const items = " + config.services[currentService].frontends[currentFrontend].preferences.localStorage, + file: "/assets/javascripts/set-localstorage.js", + runAt: "document_start", + }) + ) } if ("indexeddb" in frontend.preferences) { } diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js index 186fae43..a1c559df 100644 --- a/src/assets/javascripts/utils.js +++ b/src/assets/javascripts/utils.js @@ -59,27 +59,26 @@ function protocolHost(url) { return `${url.protocol}//${url.host}` } -async function processDefaultCustomInstances(service, name, network, document) { +async function processDefaultCustomInstances(service, frontend, network, document) { let instancesLatency - let nameNetworkElement = document.getElementById(name).getElementsByClassName(network)[0] + let frontendNetworkElement = document.getElementById(frontend).getElementsByClassName(network)[0] - let nameCustomInstances = [] - let nameCheckListElement = nameNetworkElement.getElementsByClassName("checklist")[0] + let frontendCustomInstances = [] + let frontendCheckListElement = frontendNetworkElement.getElementsByClassName("checklist")[0] await initBlackList() - let nameDefaultRedirects + let frontendDefaultRedirects let redirects, options async function getFromStorage() { return new Promise(async resolve => browser.storage.local.get(["options", "redirects", "latency"], r => { - nameDefaultRedirects = r.options[name][network].enabled - nameCustomInstances = r.options[name][network].custom + frontendDefaultRedirects = r.options[frontend][network].enabled + frontendCustomInstances = r.options[frontend][network].custom options = r.options - if (r.latency) instancesLatency = r.latency[name] ?? [] - else instancesLatency = [] + instancesLatency = r.latency[frontend] ?? [] redirects = r.redirects resolve() }) @@ -88,27 +87,26 @@ async function processDefaultCustomInstances(service, name, network, document) { await getFromStorage() - function calcNameCheckBoxes() { + function calcFrontendCheckBoxes() { let isTrue = true - for (const item of redirects[name][network]) { - if (nameDefaultRedirects === undefined) console.log(name + network + " is undefined") - if (!nameDefaultRedirects.includes(item)) { + for (const item of redirects[frontend][network]) { + if (!frontendDefaultRedirects.includes(item)) { isTrue = false break } } - for (const element of nameCheckListElement.getElementsByTagName("input")) { - element.checked = nameDefaultRedirects.includes(element.className) + for (const element of frontendCheckListElement.getElementsByTagName("input")) { + element.checked = frontendDefaultRedirects.includes(element.className) } - if (nameDefaultRedirects.length == 0) isTrue = false - nameNetworkElement.getElementsByClassName("toggle-all")[0].checked = isTrue + if (frontendDefaultRedirects.length == 0) isTrue = false + frontendNetworkElement.getElementsByClassName("toggle-all")[0].checked = isTrue } - nameCheckListElement.innerHTML = [ + frontendCheckListElement.innerHTML = [ `
Toggle All
`, - ...redirects[name][network].map(x => { + ...redirects[frontend][network].map(x => { const cloudflare = cloudflareBlackList.includes(x) ? ' cloudflare' : "" const authenticate = authenticateBlackList.includes(x) ? ' authenticate' : "" const offline = offlineBlackList.includes(x) ? ' offline' : "" @@ -132,33 +130,33 @@ async function processDefaultCustomInstances(service, name, network, document) { localise.localisePage() - calcNameCheckBoxes() - nameNetworkElement.getElementsByClassName("toggle-all")[0].addEventListener("change", async event => { - if (event.service.checked) nameDefaultRedirects = [...redirects[name][network]] - else nameDefaultRedirects = [] + calcFrontendCheckBoxes() + frontendNetworkElement.getElementsByClassName("toggle-all")[0].addEventListener("change", async event => { + if (event.target.checked) frontendDefaultRedirects = [...redirects[frontend][network]] + else frontendDefaultRedirects = [] - options[service][network].enabled = nameDefaultRedirects + options[frontend][network].enabled = frontendDefaultRedirects browser.storage.local.set({ options }) - calcNameCheckBoxes() + calcFrontendCheckBoxes() }) - for (let element of nameCheckListElement.getElementsByTagName("input")) { + for (let element of frontendCheckListElement.getElementsByTagName("input")) { if (element.className != "toggle-all") - nameNetworkElement.getElementsByClassName(element.className)[0].addEventListener("change", async event => { - if (event.service.checked) nameDefaultRedirects.push(element.className) + frontendNetworkElement.getElementsByClassName(element.className)[0].addEventListener("change", async event => { + if (event.target.checked) frontendDefaultRedirects.push(element.className) else { - let index = nameDefaultRedirects.indexOf(element.className) - if (index > -1) nameDefaultRedirects.splice(index, 1) + let index = frontendDefaultRedirects.indexOf(element.className) + if (index > -1) frontendDefaultRedirects.splice(index, 1) } - options[service][network].enabled = nameDefaultRedirects + options[frontend][network].enabled = frontendDefaultRedirects browser.storage.local.set({ options }) - calcNameCheckBoxes() + calcFrontendCheckBoxes() }) } - function calcNameCustomInstances() { - nameNetworkElement.getElementsByClassName("custom-checklist")[0].innerHTML = nameCustomInstances + function calcFrontendCustomInstances() { + frontendNetworkElement.getElementsByClassName("custom-checklist")[0].innerHTML = frontendCustomInstances .map( x => `
${x} @@ -172,30 +170,30 @@ async function processDefaultCustomInstances(service, name, network, document) { ) .join("\n") - for (const item of nameCustomInstances) { - nameNetworkElement.getElementsByClassName(`clear-${item}`)[0].addEventListener("click", async () => { - let index = nameCustomInstances.indexOf(item) - if (index > -1) nameCustomInstances.splice(index, 1) - options[service][network].custom = nameCustomInstances + for (const item of frontendCustomInstances) { + frontendNetworkElement.getElementsByClassName(`clear-${item}`)[0].addEventListener("click", async () => { + let index = frontendCustomInstances.indexOf(item) + if (index > -1) frontendCustomInstances.splice(index, 1) + options[frontend][network].custom = frontendCustomInstances browser.storage.local.set({ options }) - calcNameCustomInstances() + calcFrontendCustomInstances() }) } } - calcNameCustomInstances() - nameNetworkElement.getElementsByClassName("custom-instance-form")[0].addEventListener("submit", async event => { + calcFrontendCustomInstances() + frontendNetworkElement.getElementsByClassName("custom-instance-form")[0].addEventListener("submit", async event => { event.preventDefault() - let nameCustomInstanceInput = nameNetworkElement.getElementsByClassName("custom-instance")[0] - let url = new URL(nameCustomInstanceInput.value) + let frontendCustomInstanceInput = frontendNetworkElement.getElementsByClassName("custom-instance")[0] + let url = new URL(frontendCustomInstanceInput.value) let protocolHostVar = protocolHost(url) - if (nameCustomInstanceInput.validity.valid && !redirects[name][network].includes(protocolHostVar)) { - if (!nameCustomInstances.includes(protocolHostVar)) { - nameCustomInstances.push(protocolHostVar) - options[service][network].custom = nameCustomInstances + if (frontendCustomInstanceInput.validity.valid && !redirects[frontend][network].includes(protocolHostVar)) { + if (!frontendCustomInstances.includes(protocolHostVar)) { + frontendCustomInstances.push(protocolHostVar) + options[frontend][network].custom = frontendCustomInstances browser.storage.local.set({ options }) - nameCustomInstanceInput.value = "" + frontendCustomInstanceInput.value = "" } - calcNameCustomInstances() + calcFrontendCustomInstances() } }) } @@ -245,11 +243,12 @@ function pingOnce(href) { async function testLatency(element, instances, frontend) { return new Promise(async resolve => { let myList = {} - let latencyThreshold - let redirectsChecks = [] + let latencyThreshold, options + //let redirectsChecks = [] browser.storage.local.get(["options"], r => { latencyThreshold = r.options.latencyThreshold - redirectsChecks = r.options[frontend].clearnet.enabled + //redirectsChecks = r.options[frontend].clearnet.enabled + options = r.options }) for (const href of instances) await ping(href).then(time => { @@ -261,11 +260,9 @@ async function testLatency(element, instances, frontend) { else color = "red" if (time > latencyThreshold) { - redirectsChecks.splice(redirectsChecks.indexOf(href), 1) + options[frontend].clearnet.enabled.splice(options[frontend].clearnet.enabled.indexOf(href), 1) } - browser.storage.local.set({ [`${frontend}ClearnetRedirectsChecks`]: redirectsChecks }) - let text if (time == 5000) text = "5000ms+" else if (time > 5000) text = `ERROR: ${time - 5000}` @@ -273,6 +270,7 @@ async function testLatency(element, instances, frontend) { element.innerHTML = `${href}: ${text}` } }) + browser.storage.local.set({ options }) resolve(myList) }) } @@ -386,7 +384,7 @@ function unify() { return } - let result = await servicesHelper.unifyPreferences(url) + let result = await servicesHelper.unifyPreferences(url, currTab.id) resolve(result) } @@ -417,21 +415,21 @@ function switchInstance(test) { }) } -function latency(name, frontend, document, location) { +function latency(service, frontend, document, location) { let latencyElement = document.getElementById(`latency-${frontend}`) let latencyLabel = document.getElementById(`latency-${frontend}-label`) latencyElement.addEventListener("click", async () => { let reloadWindow = () => location.reload() latencyElement.addEventListener("click", reloadWindow) - let key = `${name} Redirects` - browser.storage.local.get(key, r => { - let redirects = r[key] + browser.storage.local.get(["redirects", "latency"], r => { + let redirects = r.redirects const oldHtml = latencyLabel.innerHTML latencyLabel.innerHTML = "..." testLatency(latencyLabel, redirects[frontend].clearnet, frontend).then(r => { - browser.storage.local.set({ [`${frontend}Latency`]: r }) + latency[frontend] = r + browser.storage.local.set({ latency }) latencyLabel.innerHTML = oldHtml - processDefaultCustomInstances(name, frontend, "clearnet", document) + processDefaultCustomInstances(service, frontend, "clearnet", document) latencyElement.removeEventListener("click", reloadWindow) }) }) diff --git a/src/config/config.json b/src/config/config.json index e2b511b9..b15c20d4 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -48,7 +48,8 @@ "sponsorblock", "theme", "volume", - "watchHistory" + "watchHistory", + "localSubscriptions" ] }, "name": "Piped", @@ -490,13 +491,13 @@ }, "lingva": { "preferences": { - "localstorage": ["isauto", "source", "target"] + "localstorage": ["isauto", "source", "target", "chakra-ui-color-mode"] }, - "name": "Lingva", + "name": "Lingva Translate", "instanceList": true } }, - "targets": ["^https?:\\/{2}translate\\.google(\\.[a-z]{2,3}){1,2}\\/"], + "targets": ["^https?:\\/{2}translate\\.google(\\.[a-z]{2,3}){1,2}\\/", "^https?:\\/{2}translate\\.libredirect\\.invalid"], "name": "Translate", "options": { "enabled": true, @@ -504,7 +505,7 @@ }, "imageType": "svgMono", "embeddable": false, - "url": "https://translate.google.com" + "url": "https://translate.libredirect.invalid" }, "maps": { "frontends": { @@ -518,7 +519,7 @@ "singleInstance": "https://www.openstreetmap.org" } }, - "targets": ["^https?:\\/{2}(((www|maps)\\.)?(google\\.).*(\\/maps)|maps\\.(google\\.).*)"], + "targets": ["^https?:\\/{2}maps\\.libredirect\\.invalid", "^https?:\\/{2}(((www|maps)\\.)?(google\\.).*(\\/maps)|maps\\.(google\\.).*)"], "name": "Maps", "options": { "enabled": true, @@ -526,16 +527,16 @@ }, "imageType": "svgMono", "embeddable": false, - "url": "https://maps.google.com" + "url": "https://maps.libredirect.invalid" }, - "sendTargets": { + "uploadFiles": { "frontends": { "send": { "name": "Send", "instanceList": "true" } }, - "targets": ["^https?:\\/{2}send\\.libredirect\\.invalid\\/?$", "^https?:\\/{2}send\\.firefox\\.com\\/?$", "^https?:\\/{2}sendfiles\\.online\\/?$"], + "targets": ["^https?:\\/{2}send\\.libredirect\\.invalid", "^https?:\\/{2}send\\.firefox\\.com\\/?$", "^https?:\\/{2}sendfiles\\.online\\/?$"], "name": "Send Files", "options": { "enabled": true }, "imageType": "svgMono", diff --git a/src/pages/background/background.js b/src/pages/background/background.js index e9bf691f..3a900609 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -6,20 +6,7 @@ import servicesHelper from "../../assets/javascripts/services.js" window.browser = window.browser || window.chrome -browser.runtime.onInstalled.addListener(details => { - function initDefaults() { - fetch("/instances/blacklist.json") - .then(response => response.text()) - .then(async data => { - browser.storage.local.clear(() => { - browser.storage.local.set({ blacklists: JSON.parse(data) }, () => { - generalHelper.initDefaults() - servicesHelper.initDefaults() - }) - }) - }) - } - +browser.runtime.onInstalled.addListener(async details => { // if (details.reason == 'install' || (details.reason == "update" && details.previousVersion != browser.runtime.getManifest().version)) { // if (details.reason == "update") // browser.storage.local.get(null, r => { @@ -38,12 +25,25 @@ browser.runtime.onInstalled.addListener(details => { case "update": switch (details.previousVersion) { case "2.2.1": - //do stuff + initDefaults() break } } }) +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() + }) + }) + }) +} + let BYPASSTABs = [] browser.webRequest.onBeforeRequest.addListener( details => { diff --git a/src/pages/options/index.html b/src/pages/options/index.html index 6ef33723..71d04fd0 100644 --- a/src/pages/options/index.html +++ b/src/pages/options/index.html @@ -84,7 +84,7 @@ - Send Files
+ Send Files
@@ -318,9 +318,9 @@ - Send Files + Send Files
- +
@@ -2818,7 +2818,7 @@

Frontend

@@ -3134,14 +3134,14 @@
-
+
-

Send Files

+

Send Files


Enable

- +

diff --git a/src/pages/options/widgets/general.js b/src/pages/options/widgets/general.js index 23ed73ee..cd5cfb47 100644 --- a/src/pages/options/widgets/general.js +++ b/src/pages/options/widgets/general.js @@ -37,7 +37,6 @@ function setOption(option, multiChoice, event) { browser.storage.local.get("options", r => { let options = r.options if (multiChoice) { - console.log(event.target.options) options[option] = event.target.options[event.target.options.selectedIndex].value } else { options[option] = event.target.checked @@ -95,6 +94,7 @@ resetSettings.addEventListener("click", async () => { .then(response => response.text()) .then(async data => { browser.storage.local.set({ blacklists: JSON.parse(data) }, async () => { + await generalHelper.initDefaults() await servicesHelper.initDefaults() location.reload() }) diff --git a/src/pages/options/widgets/services.js b/src/pages/options/widgets/services.js index 873950f3..98e068a1 100644 --- a/src/pages/options/widgets/services.js +++ b/src/pages/options/widgets/services.js @@ -77,7 +77,7 @@ function changeNetworkSettings() { changeNetworkSettings() for (const service in config.services) { divs[service] = {} - divs[service][service] = document.getElementById(`${service}_page`) + //divs[service].page = document.getElementById(`${service}_page`) for (const option in config.services[service].options) { divs[service][option] = document.getElementById(`${service}-${option}`) diff --git a/src/pages/popup/popup.html b/src/pages/popup/popup.html index d52a34b6..56e4ca14 100644 --- a/src/pages/popup/popup.html +++ b/src/pages/popup/popup.html @@ -91,7 +91,7 @@

Search

-
+ -
+ -
+
-

Send Files

- +

Send Files

+
@@ -204,7 +204,7 @@

Search

-
+ -
+ -
+
-

Send Files

- +

Send Files

+
-- cgit 1.4.1 From c1af086c2756f401d8403b259e29f1354c5e001f Mon Sep 17 00:00:00 2001 From: Hygna Date: Mon, 3 Oct 2022 06:44:49 +0100 Subject: Finished options upgrading --- src/_locales/filter.py | 8 - src/assets/images/sendFiles-icon.svg | 3 + src/assets/images/uploadFiles-icon.svg | 3 - src/assets/javascripts/services.js | 277 +++++++++++++++++---------------- src/assets/javascripts/utils.js | 8 +- src/config/config.json | 5 +- src/instances/get_instances.py | 1 + src/pages/options/index.html | 17 +- src/pages/options/widgets/general.js | 25 ++- src/pages/popup/popup.html | 12 +- src/pages/popup/popup.js | 6 +- 11 files changed, 190 insertions(+), 175 deletions(-) create mode 100644 src/assets/images/sendFiles-icon.svg delete mode 100644 src/assets/images/uploadFiles-icon.svg (limited to 'src/pages/popup/popup.html') diff --git a/src/_locales/filter.py b/src/_locales/filter.py index 581bb36c..0d5fb44d 100644 --- a/src/_locales/filter.py +++ b/src/_locales/filter.py @@ -1,12 +1,4 @@ -import requests import json -from urllib.parse import urlparse -from bs4 import BeautifulSoup -import re -from colorama import Fore, Back, Style -from urllib.parse import urlparse -import socket -import subprocess ar_json = {} diff --git a/src/assets/images/sendFiles-icon.svg b/src/assets/images/sendFiles-icon.svg new file mode 100644 index 00000000..5557664e --- /dev/null +++ b/src/assets/images/sendFiles-icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/assets/images/uploadFiles-icon.svg b/src/assets/images/uploadFiles-icon.svg deleted file mode 100644 index 5557664e..00000000 --- a/src/assets/images/uploadFiles-icon.svg +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 279c8c21..59316dfc 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -406,123 +406,115 @@ function computeService(url, returnFrontend) { } } } - // if (returnFrontend) return [null, null] - // else return null + resolve() }) }) }) } -async function switchInstance(url) { - fetch("/config/config.json") - .then(response => response.text()) - .then(configData => { - const config = JSON.parse(configData) - browser.storage.local.get(["redirects", "options"], r => { - const redirects = r.redirects - const options = r.options - const protocolHost = utils.protocolHost(url) - for (const service in config.services) { - if (!options[service].enabled) continue - if (!all(service, null, options, config, redirects).includes(protocolHost)) continue - - let instancesList = [...options[options[service].frontend][options.network].enabled, ...options[options[service].frontend][options.network].custom] - if (instancesList.length === 0 && options.networkFallback) instancesList = [...options[options[service].frontend].clearnet.enabled, ...options[options[service].frontend].clearnet.custom] - - let oldInstance - const i = instancesList.indexOf(protocolHost) - if (i > -1) { - oldInstance = instancesList[i] - instancesList.splice(i, 1) - } - if (instancesList.length === 0) return - const randomInstance = utils.getRandomInstance(instancesList) - const oldUrl = `${oldInstance}${url.pathname}${url.search}` - // This is to make instance switching work when the instance depends on the pathname, eg https://darmarit.org/searx - // Doesn't work because of .includes array method, not a top priotiry atm - return oldUrl.replace(oldInstance, randomInstance) - } - }) - }) +function switchInstance(url) { + return new Promise(async resolve => { + await init() + const protocolHost = utils.protocolHost(url) + for (const service in config.services) { + if (!all(service, null, options, config, redirects).includes(protocolHost)) continue + + let instancesList = [...options[options[service].frontend][options.network].enabled, ...options[options[service].frontend][options.network].custom] + if (instancesList.length === 0 && options.networkFallback) instancesList = [...options[options[service].frontend].clearnet.enabled, ...options[options[service].frontend].clearnet.custom] + + let oldInstance + const i = instancesList.indexOf(protocolHost) + if (i > -1) { + oldInstance = instancesList[i] + instancesList.splice(i, 1) + } + if (instancesList.length === 0) { + resolve() + return + } + const randomInstance = utils.getRandomInstance(instancesList) + const oldUrl = `${oldInstance}${url.pathname}${url.search}` + // This is to make instance switching work when the instance depends on the pathname, eg https://darmarit.org/searx + // Doesn't work because of .includes array method, not a top priotiry atm + resolve(oldUrl.replace(oldInstance, randomInstance)) + return + } + resolve() + }) } -async function reverse(url) { - fetch("/config/config.json") - .then(response => response.text()) - .then(configData => { - const config = JSON.parse(configData) - browser.storage.local.get(["redirects", "options"], r => { - const redirects = r.redirects - const options = r.options - let protocolHost = utils.protocolHost(url) - for (const service in config.services) { - if (!all(service, null, options, config, redirects).includes(protocolHost)) continue - - switch (service) { - case "instagram": - if (url.pathname.startsWith("/p")) return `https://instagram.com${url.pathname.replace("/p", "")}${url.search}` - if (url.pathname.startsWith("/u")) return `https://instagram.com${url.pathname.replace("/u", "")}${url.search}` - return config.services[service].url + url.pathname + url.search - case "youtube": - case "imdb": - case "imgur": - case "tiktok": - case "twitter": - case "reddit": - return config.services[service].url + url.pathname + url.search - default: - return - } - } - }) - }) +function reverse(url) { + return new Promise(async resolve => { + await init() + let protocolHost = utils.protocolHost(url) + for (const service in config.services) { + if (!all(service, null, options, config, redirects).includes(protocolHost)) continue + + switch (service) { + case "instagram": + if (url.pathname.startsWith("/p")) resolve(`https://instagram.com${url.pathname.replace("/p", "")}${url.search}`) + if (url.pathname.startsWith("/u")) resolve(`https://instagram.com${url.pathname.replace("/u", "")}${url.search}`) + resolve(config.services[service].url + url.pathname + url.search) + return + case "youtube": + case "imdb": + case "imgur": + case "tiktok": + case "twitter": + case "reddit": + resolve(config.services[service].url + url.pathname + url.search) + return + default: + resolve() + return + } + } + resolve() + }) } -async function unifyPreferences(url, tabId) { - fetch("/config/config.json") - .then(response => response.text()) - .then(configData => { - const config = JSON.parse(configData) - browser.storage.local.get(["options", "reidrects"], r => { - const redirects = r.redirects - const options = r.options - const protocolHost = utils.protocolHost(url) - for (const service in config.services) { - for (const frontend in config.services[service].frontends) { - if (all(service, frontend, options, config, redirects).includes(protocolHost)) { - let instancesList = [...options[frontend][options.network].enabled, ...options[frontend][options.network].custom] - if (options.networkFallback && options.network != "clearnet") instancesList.push(...options[frontend].clearnet.enabled, ...options[frontend].clearnet.custom) - - const frontend = config.services[service].frontends[frontend] - if ("cookies" in frontend.preferences) { - for (const cookie of frontend.preferences.cookies) { - utils.copyCookie(frontend, url, instancesList, cookie) - } - } - if ("localstorage" in frontend.preferences) { - browser.storage.local.set({ tmp: [frontend, frontend.preferences.localstorage] }) - browser.tabs.executeScript(tabId, { - file: "/assets/javascripts/get-localstorage.js", +function unifyPreferences(url, tabId) { + return new Promise(async resolve => { + await init() + const protocolHost = utils.protocolHost(url) + for (const service in config.services) { + for (const frontend in config.services[service].frontends) { + if (all(service, frontend, options, config, redirects).includes(protocolHost)) { + let instancesList = [...options[frontend][options.network].enabled, ...options[frontend][options.network].custom] + if (options.networkFallback && options.network != "clearnet") instancesList.push(...options[frontend].clearnet.enabled, ...options[frontend].clearnet.custom) + + const frontendObject = config.services[service].frontends[frontend] + if ("cookies" in frontendObject.preferences) { + for (const cookie of frontendObject.preferences.cookies) { + utils.copyCookie(frontendObject, url, instancesList, cookie) + } + } + if ("localstorage" in frontendObject.preferences) { + browser.storage.local.set({ tmp: [frontend, frontendObject.preferences.localstorage] }) + browser.tabs.executeScript(tabId, { + file: "/assets/javascripts/get-localstorage.js", + runAt: "document_start", + }) + for (const instance of instancesList) + browser.tabs.create({ url: instance }, tab => + browser.tabs.executeScript(tab.id, { + file: "/assets/javascripts/set-localstorage.js", runAt: "document_start", }) - for (const instance of instancesList) - browser.tabs.create({ url: instance }, tab => - browser.tabs.executeScript(tab.id, { - file: "/assets/javascripts/set-localstorage.js", - runAt: "document_start", - }) - ) - } - if ("indexeddb" in frontend.preferences) { - } - if ("token" in frontend.preferences) { - } - return true - } + ) + } + /* + if ("indexeddb" in frontendObject.preferences) { } + if ("token" in frontendObject.preferences) { + } + */ + resolve(true) + return } - }) - }) + } + } + }) } async function setRedirects(redirects) { @@ -612,46 +604,67 @@ function upgradeOptions() { fetch("/config/config.json") .then(response => response.text()) .then(configData => { - browser.storage.local.get(["options", "exceptions", "theme", "popupFrontends", "autoRedirect", "firstPartyIsolate"], r => { + browser.storage.local.get(null, r => { let options = r.options let latency = {} const config = JSON.parse(configData) options.exceptions = r.exceptions if (r.theme != "DEFAULT") options.theme = r.theme options.popupServices = r.popupFrontends + let tmp = options.popupServices.indexOf("tikTok") + if (tmp > -1) { + options.popupServices.splice(tmp, 1) + options.popupServices.push("tiktok") + } + tmp = options.popupServices.indexOf("sendTarget") + if (tmp > -1) { + options.popupServices.splice(tmp, 1) + options.popupServices.push("sendFiles") + } options.firstPartyIsolate = r.firstPartyIsolate options.autoRedirect = r.autoRedirect + switch (r.onlyEmbeddedVideo) { + case "onlyNotEmbedded": + options.youtube.redirectType = "main_frame" + case "onlyEmbedded": + options.youtube.redirectType = "sub_frame" + case "both": + options.youtube.redirectType = "both" + } for (const service in config.services) { - browser.storage.local.get([`disable${utils.camelCase(service)}`, `${service}RedirectType`, `${service}Frontend`, `${service}Latency`, `${service}EmbedFrontend`], r => { - if (r) { - options[service].enabled = !r["disable" + utils.camelCase(service)] - if (r[service + "Frontend"]) { - if (r[service + "Frontend"] == "yatte") options[service].frontend = "yattee" - else options[service].frontend = r[service + "Frontend"] - } - if (r[service + "RedirectType"]) options[service].redirectType = r[service + "RedirectType"] - if (r[service + "EmbedFrontend"] && (service != "youtube" || r[service + "EmbedFrontend"] == "invidious" || "piped")) options[service].embedFrontend = r[service + "EmbedFrontend"] - for (const frontend in config.services[service].frontends) { - browser.local.storage.get(`${frontend}Latency`, r => { - if (r) latency[frontend] = r[frontend + "Latency"] - for (const network in config.networks) { - let protocol - if (network == "clearnet") protocol = "normal" - else protocol = network - browser.storage.local.get([`${frontend}${utils.camelCase(protocol)}RedirectsChecks`, `${frontend}${utils.camelCase(protocol)}CustomRedirects`], r => { - if (r) { - options[frontend][network].checks = r[frontend + utils.camelCase(protocol) + "RedirectsChecks"] - options[frontend][network].custom = r[frontend + utils.camelCase(protocol) + "CustomRedirects"] - } - }) - } - }) + let oldService + switch (service) { + case "tiktok": + oldService = "tikTok" + break + case "sendFiles": + oldService = "sendTarget" + break + default: + oldService = service + } + options[service].enabled = !r["disable" + utils.camelCase(oldService)] + if (r[oldService + "Frontend"]) { + if (r[oldService + "Frontend"] == "yatte") options[service].frontend = "yattee" + else options[service].frontend = r[oldService + "Frontend"] + } + if (r[oldService + "RedirectType"]) options[service].redirectType = r[oldService + "RedirectType"] + if (r[oldService + "EmbedFrontend"] && (service != "youtube" || r[oldService + "EmbedFrontend"] == "invidious" || r[oldService + "EmbedFrontend"] == "piped")) + options[service].embedFrontend = r[oldService + "EmbedFrontend"] + for (const frontend in config.services[service].frontends) { + if (r[frontend + "Latency"]) latency[frontend] = r[frontend + "Latency"] + for (const network in config.networks) { + let protocol + if (network == "clearnet") protocol = "normal" + else protocol = network + if (r[frontend + utils.camelCase(protocol) + "RedirectsChecks"]) { + options[frontend][network].enabled = r[frontend + utils.camelCase(protocol) + "RedirectsChecks"] + options[frontend][network].custom = r[frontend + utils.camelCase(protocol) + "CustomRedirects"] } } - }) + } } - browser.storage.local.set({ options, latency }) - resolve() + browser.storage.local.set({ options, latency }, () => resolve()) }) }) }) diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js index 26fe11d6..056bbc00 100644 --- a/src/assets/javascripts/utils.js +++ b/src/assets/javascripts/utils.js @@ -342,7 +342,7 @@ function getPreferencesFromToken(frontend, targetUrl, urls, name, endpoint) { }) } -function copyRaw(test, copyRawElement, config) { +function copyRaw(test, copyRawElement) { return new Promise(resolve => { browser.tabs.query({ active: true, currentWindow: true }, async tabs => { let currTab = tabs[0] @@ -355,7 +355,7 @@ function copyRaw(test, copyRawElement, config) { return } - let newUrl = servicesHelper.reverse(url, config) + const newUrl = await servicesHelper.reverse(url) if (newUrl) { resolve(newUrl) @@ -387,9 +387,7 @@ function unify() { return } - const result = await servicesHelper.unifyPreferences(url, currTab.id) - - resolve(result) + resolve(await servicesHelper.unifyPreferences(url, currTab.id)) } }) }) diff --git a/src/config/config.json b/src/config/config.json index b15c20d4..6866453c 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -22,7 +22,8 @@ "frontends": { "invidious": { "preferences": { - "cookies": ["PREFS"] + "cookies": ["PREFS"], + "localstorage": ["dark_mode"] }, "name": "Invidious", "embeddable": true, @@ -529,7 +530,7 @@ "embeddable": false, "url": "https://maps.libredirect.invalid" }, - "uploadFiles": { + "sendFiles": { "frontends": { "send": { "name": "Send", diff --git a/src/instances/get_instances.py b/src/instances/get_instances.py index 06b547b3..9a53f927 100644 --- a/src/instances/get_instances.py +++ b/src/instances/get_instances.py @@ -431,6 +431,7 @@ def peertube(): def isValid(url): # This code is contributed by avanitrachhadiya2155 try: + url.encode('ascii') result = urlparse(url) return all([result.scheme, result.netloc]) except Exception: diff --git a/src/pages/options/index.html b/src/pages/options/index.html index 2549566c..5421bb81 100644 --- a/src/pages/options/index.html +++ b/src/pages/options/index.html @@ -84,7 +84,7 @@ - Send Files
+ Send Files
@@ -150,11 +150,6 @@
-
- +
@@ -3139,14 +3134,14 @@
-
+
-

Send Files

+

Send Files


Enable

- +

diff --git a/src/pages/options/widgets/general.js b/src/pages/options/widgets/general.js index 1a2f44c6..92632f23 100644 --- a/src/pages/options/widgets/general.js +++ b/src/pages/options/widgets/general.js @@ -49,16 +49,16 @@ function setOption(option, multiChoice, event) { let exportSettingsElement = document.getElementById("export-settings") function exportSettings() { - browser.storage.local.get(null, result => { - let resultString = JSON.stringify(result, null, " ") - exportSettingsElement.href = "data:application/json;base64," + btoa(encodeURI(resultString)) + browser.storage.local.get("options", result => { + result.options.version = browser.runtime.getManifest().version + let resultString = JSON.stringify(result.options, null, " ") + exportSettingsElement.href = "data:application/json;base64," + btoa(resultString) exportSettingsElement.download = "libredirect-settings.json" }) } exportSettings() document.getElementById("general_page").addEventListener("click", exportSettings) -document.getElementById("test").addEventListener("click", servicesHelper.upgradeOptions) let importSettingsElement = document.getElementById("import-settings") let importSettingsElementText = document.getElementById("import_settings_text") @@ -70,7 +70,22 @@ importSettingsElement.addEventListener("change", () => { reader.onload = async () => { const data = JSON.parse(reader.result) if ("theme" in data && "disableImgur" in data && "imgurRedirects" in data) { - browser.storage.local.clear(() => browser.storage.local.set({ ...data }, () => location.reload())) + browser.storage.local.clear(() => + browser.storage.local.set({ ...data }, () => { + 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() + await servicesHelper.upgradeOptions() + location.reload() + }) + }) + }) + ) + } else if ("version" in data) { + browser.storage.local.clear(() => browser.storage.local.set({ options: data }, () => location.reload())) } else { console.log("incompatible settings") importError() diff --git a/src/pages/popup/popup.html b/src/pages/popup/popup.html index 56e4ca14..b5076635 100644 --- a/src/pages/popup/popup.html +++ b/src/pages/popup/popup.html @@ -107,13 +107,13 @@

Maps

-
+
-

Send Files

- +

Send Files

+
@@ -220,13 +220,13 @@

Maps

-
+
-

Send Files

- +

Send Files

+
diff --git a/src/pages/popup/popup.js b/src/pages/popup/popup.js index 05dd70f7..ed1546c7 100644 --- a/src/pages/popup/popup.js +++ b/src/pages/popup/popup.js @@ -26,7 +26,7 @@ utils.switchInstance(true).then(r => { else document.getElementById("change_instance").addEventListener("click", () => utils.switchInstance(false)) }) -utils.copyRaw(true, null, config).then(r => { +utils.copyRaw(true).then(r => { if (!r) document.getElementById("copy_raw_div").style.display = "none" else { const copy_raw = document.getElementById("copy_raw") @@ -81,13 +81,13 @@ browser.storage.local.get("options", r => { let service = await serviceHelper.computeService(url, true) let frontend if (service) { - if (service[1]) { + if (service[0]) { frontend = service[1] service = service[0] } divs[service].current.classList.remove("hide") divs[service].all.classList.add("hide") - if (config.services[service].frontends[frontend].preferences && !config.services[service].frontends[frontend].preferences.token) { + if (frontend && config.services[service].frontends[frontend].preferences && !config.services[service].frontends[frontend].preferences.token) { const unify = document.getElementById("unify") const textElement = document.getElementById("unify").getElementsByTagName("h4")[0] unify.addEventListener("click", () => { -- cgit 1.4.1 From ebc1259ca4ade09e53af17ee86b67eb09f0f9c75 Mon Sep 17 00:00:00 2001 From: Hygna Date: Mon, 3 Oct 2022 19:49:12 +0100 Subject: Squashed many bugs --- src/assets/javascripts/services.js | 2 +- src/config/config.json | 2 +- src/instances/get_instances.py | 39 +++++++++++++++++++++-------- src/pages/options/index.html | 38 ++++++++++++++-------------- src/pages/options/widgets/general.ejs | 4 +-- src/pages/options/widgets/general.js | 47 +++++++++++++++++++---------------- src/pages/popup/popup.html | 4 +-- src/pages/stylesheets/styles.css | 13 ++++++++++ 8 files changed, 91 insertions(+), 58 deletions(-) (limited to 'src/pages/popup/popup.html') diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 59316dfc..afd7906f 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -76,7 +76,7 @@ function redirect(url, type, initiator) { } if (Object.keys(config.services[service].frontends).length > 1) { - if (type == "sub_frame") frontend = options[service].embedFrontend + if (type == "sub_frame" && config.services[service].embeddable && !config.services[service].frontends[options[service].frontend].embeddable) frontend = options[service].embedFrontend else frontend = options[service].frontend } else frontend = Object.keys(config.services[service].frontends)[0] diff --git a/src/config/config.json b/src/config/config.json index 6866453c..09c95bbb 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -279,7 +279,7 @@ "options": { "enabled": false }, "imageType": "svg", "embeddable": false, - "url": "https://wikipedia.com" + "url": "https://wikipedia.org" }, "medium": { "frontends": { diff --git a/src/instances/get_instances.py b/src/instances/get_instances.py index 9a53f927..c789f551 100644 --- a/src/instances/get_instances.py +++ b/src/instances/get_instances.py @@ -25,16 +25,33 @@ with open('./src/config/config.json', 'rt') as tmp: def filterLastSlash(urlList): tmp = {} - for x in urlList: - tmp[x] = {} - for y in urlList[x]: - tmp[x][y] = [] - for z in urlList[x][y]: - if z.endswith('/'): - tmp[x][y].append(z[:-1]) - print(Fore.YELLOW + "Fixed " + Style.RESET_ALL + z) + for frontend in urlList: + tmp[frontend] = {} + for network in urlList[frontend]: + tmp[frontend][network] = [] + for url in urlList[frontend][network]: + if url.endswith('/'): + tmp[frontend][network].append(url[:-1]) + print(Fore.YELLOW + "Fixed " + Style.RESET_ALL + url) else: - tmp[x][y].append(z) + tmp[frontend][network].append(url) + return tmp + + +def idnaEncode(urlList): + tmp = {} + for frontend in urlList: + tmp[frontend] = {} + for network in urlList[frontend]: + tmp[frontend][network] = [] + for url in urlList[frontend][network]: + try: + encodedUrl = url.encode("idna").decode("utf8") + tmp[frontend][network].append(encodedUrl) + if (encodedUrl != url): + print(Fore.YELLOW + "Fixed " + Style.RESET_ALL + url) + except Exception: + tmp[frontend][network].append(url) return tmp @@ -247,7 +264,7 @@ def piped(): _list['loki'] = [] r = requests.get( 'https://raw.githubusercontent.com/wiki/TeamPiped/Piped/Instances.md') - + tmp = re.findall( r'(?:[^\s\/]+\.)+[a-zA-Z]+ (?:\(Official\) )?\| (https:\/{2}(?:[^\s\/]+\.)+[a-zA-Z]+) \| ', r.text) for item in tmp: @@ -431,7 +448,6 @@ def peertube(): def isValid(url): # This code is contributed by avanitrachhadiya2155 try: - url.encode('ascii') result = urlparse(url) return all([result.scheme, result.netloc]) except Exception: @@ -465,6 +481,7 @@ hyperpipe() facil() simpleertube() mightyList = filterLastSlash(mightyList) +mightyList = idnaEncode(mightyList) cloudflare = [] authenticate = [] diff --git a/src/pages/options/index.html b/src/pages/options/index.html index 5421bb81..d79da014 100644 --- a/src/pages/options/index.html +++ b/src/pages/options/index.html @@ -116,7 +116,7 @@
-

Fallback to normal if no instances are available for the current network

+

Fallback to clearnet if no instances are available for the current network

@@ -182,56 +182,56 @@
- Youtube + Youtube
- YT Music + YT Music
- Twitter + Twitter
- Instagram + Instagram
- TikTok + TikTok
- Reddit + Reddit
- Imgur + Imgur
- Wikipedia + Wikipedia
@@ -243,42 +243,42 @@ - Medium + Medium
- Quora + Quora
- IMDb + IMDb
- Reuters + Reuters
- PeerTube + PeerTube
- LBRY + LBRY
@@ -288,7 +288,7 @@ - Search + Search
@@ -298,7 +298,7 @@ - Translate + Translate
@@ -308,7 +308,7 @@ - Maps + Maps
@@ -318,7 +318,7 @@ - Send Files + Send Files diff --git a/src/pages/options/widgets/general.ejs b/src/pages/options/widgets/general.ejs index 8f7ab029..77028ac2 100644 --- a/src/pages/options/widgets/general.ejs +++ b/src/pages/options/widgets/general.ejs @@ -21,7 +21,7 @@
-

Fallback to normal if no instances are available for the current network

+

Fallback to clearnet if no instances are available for the current network

@@ -92,7 +92,7 @@ <% } else { _%> <%- include ('src/assets/images/' + service + '-icon.svg') %> <% } _%> - <%= config.services[service].name %> + <%= config.services[service].name %> diff --git a/src/pages/options/widgets/general.js b/src/pages/options/widgets/general.js index 92632f23..a58ca3e6 100644 --- a/src/pages/options/widgets/general.js +++ b/src/pages/options/widgets/general.js @@ -28,7 +28,7 @@ async function getConfig() { }) } -function setOption(option, multiChoice, event) { +function setOption(option, type, event) { browser.storage.local.get("options", r => { let options = r.options browser.storage.local.set({ options }) @@ -36,13 +36,15 @@ function setOption(option, multiChoice, event) { browser.storage.local.get("options", r => { let options = r.options - if (multiChoice) { + if (type == "select") { options[option] = event.target.options[event.target.options.selectedIndex].value - } else { + } else if (type == "checkbox") { options[option] = event.target.checked + } else if (type == "range") { + options[option] = event.target.value } + browser.storage.local.set({ options }) - location.reload() }) } @@ -120,30 +122,30 @@ resetSettings.addEventListener("click", async () => { let autoRedirectElement = document.getElementById("auto-redirect") autoRedirectElement.addEventListener("change", event => { - setOption("autoRedirect", false, event) + setOption("autoRedirect", "checkbox", event) }) let themeElement = document.getElementById("theme") themeElement.addEventListener("change", event => { - setOption("theme", true, event) + setOption("theme", "select", event) location.reload() }) let networkElement = document.getElementById("network") networkElement.addEventListener("change", event => { - setOption("network", true, event) + setOption("network", "select", event) location.reload() }) let networkFallbackCheckbox = document.getElementById("network-fallback-checkbox") networkFallbackCheckbox.addEventListener("change", event => { - setOption("networkFallback", false, event) + setOption("networkFallback", "checkbox", event) }) let latencyOutput = document.getElementById("latency-output") let latencyInput = document.getElementById("latency-input") latencyInput.addEventListener("change", event => { - setOption("latencyThreshold", false, event) + setOption("latencyThreshold", "range", event) }) latencyInput.addEventListener("input", event => { latencyOutput.value = event.target.value @@ -153,18 +155,19 @@ let nameCustomInstanceInput = document.getElementById("exceptions-custom-instanc let instanceTypeElement = document.getElementById("exceptions-custom-instance-type") let instanceType = "url" -let popupServices - await getConfig() for (const service in config.services) { document.getElementById(service).addEventListener("change", event => { - if (event.target.checked && !popupServices.includes(service)) popupServices.push(service) - else if (popupServices.includes(service)) { - var index = popupServices.indexOf(service) - if (index !== -1) popupServices.splice(index, 1) - } - browser.storage.local.set({ popupServices }) + browser.storage.local.get("options", r => { + let options = r.options + if (event.target.checked && !options.popupServices.includes(service)) options.popupServices.push(service) + else if (options.popupServices.includes(service)) { + var index = options.popupServices.indexOf(service) + if (index !== -1) options.popupServices.splice(index, 1) + } + browser.storage.local.set({ options }) + }) }) } // const firstPartyIsolate = document.getElementById('firstPartyIsolate'); @@ -176,13 +179,14 @@ browser.storage.local.get("options", r => { networkElement.value = r.options.network networkFallbackCheckbox.checked = r.options.networkFallback latencyOutput.value = r.options.latencyThreshold + let options = r.options // firstPartyIsolate.checked = r.firstPartyIsolate; - let networkFallbackElement = document.getElementById("network-fallback") + //let networkFallbackElement = document.getElementById("network-fallback") if (networkElement.value == "clearnet") { - networkFallbackElement.style.display = "none" + networkFallbackCheckbox.disabled = true } else { - networkFallbackElement.style.display = "block" + networkFallbackCheckbox.disabled = false } instanceTypeElement.addEventListener("change", event => { @@ -251,6 +255,5 @@ browser.storage.local.get("options", r => { calcExceptionsCustomInstances() }) - popupServices = r.options.popupServices - for (const service in config.services) document.getElementById(service).checked = popupServices.includes(service) + for (const service in config.services) document.getElementById(service).checked = options.popupServices.includes(service) }) diff --git a/src/pages/popup/popup.html b/src/pages/popup/popup.html index b5076635..54c4fefa 100644 --- a/src/pages/popup/popup.html +++ b/src/pages/popup/popup.html @@ -43,7 +43,7 @@

Imgur

-
+

Wikipedia

@@ -156,7 +156,7 @@

Imgur

-
+

Wikipedia

diff --git a/src/pages/stylesheets/styles.css b/src/pages/stylesheets/styles.css index 06abab3a..eb599656 100644 --- a/src/pages/stylesheets/styles.css +++ b/src/pages/stylesheets/styles.css @@ -80,11 +80,13 @@ select { margin: 0; max-width: 500px; border-radius: 3px; + cursor: pointer; } input[type="url"], input[type="text"] { width: 400px; + cursor: text; } input:invalid { @@ -141,6 +143,7 @@ input[type="range"] { height: 7px; border-radius: 50px; background: var(--text); + cursor: ew-resize; } input[type="range"]:hover { @@ -464,3 +467,13 @@ div.about > div { div.about h4 { width: auto; } + +select:disabled { + opacity: 0.6; + cursor: not-allowed; +} + +input:disabled { + opacity: 0.6; + cursor: not-allowed; +} -- cgit 1.4.1 From a96f3188b7eac79f19f2bd438b13a310d3cea90b Mon Sep 17 00:00:00 2001 From: Hygna Date: Wed, 5 Oct 2022 17:29:27 +0100 Subject: Changes: Added BreezeWiki as a frontend for Fandom Closes https://github.com/libredirect/libredirect/issues/444 Futureproofed bug caused by adding new frontend/service --- src/assets/images/fandom-icon.svg | 1 + src/assets/javascripts/services.js | 56 +++++++++++++++++ src/config/config.json | 14 +++++ src/instances/blacklist.json | 23 ++----- src/instances/data.json | 115 ++++++++--------------------------- src/instances/get_instances.py | 5 ++ src/pages/background/background.js | 3 + src/pages/options/index.html | 120 +++++++++++++++++++++++++++++++++++++ src/pages/popup/popup.html | 10 ++++ 9 files changed, 238 insertions(+), 109 deletions(-) create mode 100644 src/assets/images/fandom-icon.svg (limited to 'src/pages/popup/popup.html') diff --git a/src/assets/images/fandom-icon.svg b/src/assets/images/fandom-icon.svg new file mode 100644 index 00000000..0cd873bf --- /dev/null +++ b/src/assets/images/fandom-icon.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 572a6a9c..d7cb520b 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -386,6 +386,11 @@ function redirect(url, type, initiator) { return `${randomInstance}/${params.sl}/${params.tl}/${params.text}` } return randomInstance + case "breezeWiki": + let wiki = url.hostname.match(/^[a-zA-Z0-9]+(?=\.fandom\.com)/) + if (wiki == "www" || !wiki) wiki = "" + else wiki = "/" + wiki + return `${randomInstance}${wiki}${url.pathname}${url.search}`.replace(/Special:Search\?query/, "search?q") default: return `${randomInstance}${url.pathname}${url.search}` } @@ -685,6 +690,56 @@ function upgradeOptions() { }) } +function processUpdate() { + return new Promise(resolve => { + fetch("/instances/data.json") + .then(response => response.text()) + .then(data => { + fetch("/config/config.json") + .then(response => response.text()) + .then(configData => { + browser.storage.local.get(["options", "blacklists", "targets"], r => { + let redirects = JSON.parse(data) + let options = r.options + let targets = r.targets + let config = JSON.parse(configData) + for (const service in config.services) { + if (!options[service]) { + options[service] = {} + if (config.services[service].targets == "datajson") { + targets[service] = redirects[service] + } + for (const defaultOption in config.services[service].options) { + options[service][defaultOption] = config.services[service].options[defaultOption] + } + } + for (const frontend in config.services[service].frontends) { + if (!options[service][frontend]) { + if (config.services[service].frontends[frontend].instanceList) { + options[frontend] = {} + for (const network in config.networks) { + options[frontend][network] = {} + options[frontend][network].enabled = JSON.parse(data)[frontend][network] + options[frontend][network].custom = [] + } + for (const blacklist in r.blacklists) { + for (const instance of r.blacklists[blacklist]) { + let i = options[frontend].clearnet.enabled.indexOf(instance) + if (i > -1) options[frontend].clearnet.enabled.splice(i, 1) + } + } + } + } + } + } + browser.storage.local.set({ redirects, options, targets }) + resolve() + }) + }) + }) + }) +} + export default { redirect, computeService, @@ -694,4 +749,5 @@ export default { setRedirects, initDefaults, upgradeOptions, + processUpdate, } diff --git a/src/config/config.json b/src/config/config.json index fde17a02..61195830 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -362,6 +362,20 @@ "embeddable": false, "url": "https://reuters.com" }, + "fandom": { + "frontends": { + "breezeWiki": { + "name": "BreezeWiki", + "instanceList": true + } + }, + "targets": ["^https?:\\/{2}(?:[a-zA-Z0-9]+\\.)?fandom\\.com(?=(?:\\/wiki)|(?:\\/?$))"], + "name": "Fandom", + "options": { "enabled": true }, + "imageType": "svg", + "embeddable": false, + "url": "https://fandom.com" + }, "peertube": { "frontends": { "simpleertube": { diff --git a/src/instances/blacklist.json b/src/instances/blacklist.json index 90febd0a..d75c36d8 100644 --- a/src/instances/blacklist.json +++ b/src/instances/blacklist.json @@ -28,18 +28,6 @@ "https://n.sneed.network", "https://nitter.twei.space", "https://nitter.d420.de", - "https://libreddit.domain.glass", - "https://r.nf", - "https://libreddit.hu", - "https://lr.stilic.ml", - "https://reddi.tk", - "https://r.walkx.org", - "https://libreddit.yonalee.eu", - "https://libreddit.winscloud.net", - "https://r.ahwx.org", - "https://reddit.dr460nf1r3.org", - "https://libreddit.encrypted-data.xyz", - "https://libreddit.eu.org", "https://teddit.domain.glass", "https://teddit.httpjames.space", "https://teddit.encrypted-data.xyz", @@ -73,18 +61,14 @@ "https://nhanh.cloud", "https://nitter.winscloud.net", "https://ntr.odyssey346.dev", - "https://libreddit.yonalee.eu", - "https://libreddit.winscloud.net", - "https://libreddit.notyourcomputer.net", "https://teddit.ggc-project.de", "https://teddit.tokhmi.xyz", - "https://wiki.privacytools.io", "https://quetre.odyssey346.dev", + "https://simplytranslate.org", "https://st.odyssey346.dev", "https://jsearch.pw", "https://searx.gnu.style", "https://searx.semipvt.com", - "https://searx.tyil.nl", "https://etsi.me", "https://search.zzls.xyz", "https://searx.ericaftereric.top", @@ -93,7 +77,10 @@ "https://whoogle.esmailelbob.xyz", "https://search.wef.lol", "https://i.bcow.xyz", + "https://rimgo.totaldarkness.net", + "https://imgur.artemislena.eu", "https://lbry.bcow.xyz", - "https://beatbump.ml" + "https://beatbump.ml", + "https://bw.odyssey346.dev" ] } \ No newline at end of file diff --git a/src/instances/data.json b/src/instances/data.json index fac7962d..eaefc4ed 100644 --- a/src/instances/data.json +++ b/src/instances/data.json @@ -13,19 +13,20 @@ "https://invidious.sethforprivacy.com", "https://invidious.flokinet.to", "https://inv.bp.projectsegfau.lt", - "https://inv.vern.cc", "https://invidious.nerdvpn.de", "https://invidious.projectsegfau.lt", "https://invidious.rhyshl.live", "https://inv.privacy.com.de", "https://invidious.slipfox.xyz", - "https://invidious.esmailelbob.xyz", "https://youtube.076.ne.jp", + "https://invidious.esmailelbob.xyz", + "https://inv.vern.cc", "https://invidious.namazso.eu" ], "tor": [ - "http://w6ijuptxiku4xpnnaetxvnkc5vqcdu7mgns2u77qefoixi63vbvnpnqd.onion", "http://c7hqkpkpemu6e7emz5b4vyz7idjgdvgaaa3dyimmeojqbgpea3xqjoid.onion", + "http://w6ijuptxiku4xpnnaetxvnkc5vqcdu7mgns2u77qefoixi63vbvnpnqd.onion", + "http://kbjggqkzv65ivcqj6bumvp337z6264huv5kpkwuv6gu5yjiskvan7fad.onion", "http://grwp24hodrefzvjjuccrkw3mjq4tzhaaq32amf33dzpmuxe7ilepcmad.onion", "http://osbivz6guyeahrwp2lnwyjk2xos342h4ocsxyqrlaopqjuhwn2djiiyd.onion", "http://u2cvlit75owumwpy4dj2hsmvkq7nvrclkpht7xgyye2pyoxhpmclkrad.onion", @@ -33,8 +34,7 @@ "http://invidious.esmail5pdn24shtvieloeedh7ehz3nrwcdivnfhfcedl7gf4kwddhkqd.onion", "http://inv.vernccvbvyi5qhfzyqengccj7lkove6bjot2xhh5kajhwvidqafczrad.onion", "http://am74vkcrjp2d5v36lcdqgsj2m6x36tbrkhsruoegwfcizzabnfgf5zyd.onion", - "http://ng27owmagn5amdm7l5s3rsqxwscl5ynppnis5dqcasogkyxcfqn7psid.onion", - "http://kbjggqkzv65ivcqj6bumvp337z6264huv5kpkwuv6gu5yjiskvan7fad.onion" + "http://ng27owmagn5amdm7l5s3rsqxwscl5ynppnis5dqcasogkyxcfqn7psid.onion" ], "i2p": [], "loki": [] @@ -51,9 +51,7 @@ "https://piped.garudalinux.org", "https://y.rivo.lol", "https://yt.jae.fi", - "https://piped.mint.lgbt", "https://il.ax", - "https://piped.esmailelbob.xyz", "https://piped.projectsegfau.lt", "https://piped.privacydev.net", "https://piped.smnz.de", @@ -208,7 +206,8 @@ "https://nitter.caioalonso.com", "https://nitter.at", "https://nitter.drivet.xyz", - "https://nitter.pw" + "https://nitter.pw", + "https://nitter.nicfab.eu" ], "tor": [ "http://nitter7bryz3jv7e3uekphigvmoyoem4al3fynerxkj22dmoxoq553qd.onion", @@ -261,87 +260,8 @@ "loki": [] }, "libreddit": { - "clearnet": [ - "https://libredd.it", - "https://libreddit.spike.codes", - "https://libreddit.dothq.co", - "https://libreddit.kavin.rocks", - "https://reddit.invak.id", - "https://reddit.phii.me", - "https://lr.riverside.rocks", - "https://libreddit.strongthany.cc", - "https://libreddit.database.red", - "https://libreddit.privacy.com.de", - "https://libreddit.domain.glass", - "https://libreddit.sugoma.tk", - "https://libreddit.jamiethalacker.dev", - "https://reddit.artemislena.eu", - "https://r.nf", - "https://libreddit.some-things.org", - "https://reddit.stuehieyr.com", - "https://lr.mint.lgbt", - "https://libreddit.igna.rocks", - "https://libreddit.autarkic.org", - "https://libreddit.flux.industries", - "https://libreddit.drivet.xyz", - "https://lr.oversold.host", - "https://libreddit.de", - "https://libreddit.pussthecat.org", - "https://libreddit.mutahar.rocks", - "https://libreddit.northboot.xyz", - "https://leddit.xyz", - "https://de.leddit.xyz", - "https://lr.cowfee.moe", - "https://libreddit.hu", - "https://libreddit.totaldarkness.net", - "https://libreddit.esmailelbob.xyz", - "https://lr.vern.cc", - "https://libreddit.nl", - "https://lr.stilic.ml", - "https://reddi.tk", - "https://libreddit.bus-hit.me", - "https://libreddit.datatunnel.xyz", - "https://libreddit.crewz.me", - "https://r.walkx.org", - "https://libreddit.kylrth.com", - "https://libreddit.yonalee.eu", - "https://libreddit.winscloud.net", - "https://libreddit.tiekoetter.com", - "https://reddit.rtrace.io", - "https://libreddit.lunar.icu", - "https://libreddit.privacydev.net", - "https://libreddit.notyourcomputer.net", - "https://r.ahwx.org", - "https://bob.fr.to", - "https://reddit.beparanoid.de", - "https://libreddit.dcs0.hu", - "https://reddit.dr460nf1r3.org", - "https://rd.jae.su", - "https://libreddit.mha.fi", - "https://libreddit.foss.wtf", - "https://libreddit.encrypted-data.xyz", - "https://libreddit.eu.org", - "https://l.opnxng.com" - ], - "tor": [ - "http://spjmllawtheisznfs7uryhxumin26ssv2draj7oope3ok3wuhy43eoyd.onion", - "http://fwhhsbrbltmrct5hshrnqlqygqvcgmnek3cnka55zj4y7nuus5muwyyd.onion", - "http://kphht2jcflojtqte4b4kyx7p2ahagv4debjj32nre67dxz7y57seqwyd.onion", - "http://inytumdgnri7xsqtvpntjevaelxtgbjqkuqhtf6txxhwbll2fwqtakqd.onion", - "http://liredejj74h5xjqr2dylnl5howb2bpikfowqoveub55ru27x43357iid.onion", - "http://kzhfp3nvb4qp575vy23ccbrgfocezjtl5dx66uthgrhu7nscu6rcwjyd.onion", - "http://ecue64ybzvn6vjzl37kcsnwt4ycmbsyf74nbttyg7rkc3t3qwnj7mcyd.onion", - "http://ledditqo2mxfvlgobxnlhrkq4dh34jss6evfkdkb2thlvy6dn4f4gpyd.onion", - "http://libredoxhxwnmsb6dvzzd35hmgzmawsq5i764es7witwhddvpc2razid.onion", - "http://libreddit.2syis2nnyytz6jnusnjurva4swlaizlnleiks5mjp46phuwjbdjqwgqd.onion", - "http://ol5begilptoou34emq2sshf3may3hlblvipdjtybbovpb7c7zodxmtqd.onion", - "http://lbrdtjaj7567ptdd4rv74lv27qhxfkraabnyphgcvptl64ijx2tijwid.onion", - "http://libreddit.lqs5fjmajyp7rvp4qvyubwofzi6d4imua7vs237rkc4m5qogitqwrgyd.onion", - "http://reddit.prnoid54e44a4bduq5due64jkk7wcnkxcp5kv3juncm7veptjcqudgyd.onion", - "http://inz6tbezfwzexva6dize4cqraj2tjdhygxabmcgysccesvw2pybzhbyd.onion", - "http://libreddit.micohauwkjbyw5meacrb4ipicwvwg4xtzl7y7viv53kig2mdcsvwkyyd.onion", - "http://lr.vernccvbvyi5qhfzyqengccj7lkove6bjot2xhh5kajhwvidqafczrad.onion" - ], + "clearnet": [], + "tor": [], "i2p": [], "loki": [] }, @@ -596,8 +516,10 @@ "http://3afisqjw2rxm6z7mmstyt5rx75qfqrgxnkzftknbp2vhipr2nrmrjdyd.onion", "http://yra4tke2pwcnatxjkufpw6kvebu3h3ti2jca2lcdpgx3mpwol326lzid.onion", "http://z5vawdol25vrmorm4yydmohsd4u6rdoj2sylvoi3e3nqvxkvpqul7bqd.onion", + "http://searxdr3pqz4nydgnqocsia2xbywptxbkympa2emn7zlgggrir4bkfad.onion", "http://zbuc3bbzbfdqqo2x46repx2ddajbha6fpsjeeptjhhhhzji3zopxdqyd.onion", "http://f4qfqajszpx5b7itzxt6mb7kj4ktpgbdq7lq6xaiqyqx6a7de3epptad.onion", + "http://searx.esmail5pdn24shtvieloeedh7ehz3nrwcdivnfhfcedl7gf4kwddhkqd.onion", "http://searx.micohauwkjbyw5meacrb4ipicwvwg4xtzl7y7viv53kig2mdcsvwkyyd.onion" ], "i2p": [ @@ -694,8 +616,6 @@ "http://searxngg6zleq6ceboe5ltkyo4hyrb3aaycrgzmrljv3jjlb5vcytead.onion", "http://gbat2pbpg7ys3fi3pbp64667tt5x66mg45xok35bxdw7v55brm7a27yd.onion", "http://b2c7fvbhnfvwnl6oh2tydhzfx4i37kmmrycq42heqbbe7wovq3uzenid.onion", - "http://searxdr3pqz4nydgnqocsia2xbywptxbkympa2emn7zlgggrir4bkfad.onion", - "http://searx.esmail5pdn24shtvieloeedh7ehz3nrwcdivnfhfcedl7gf4kwddhkqd.onion", "http://searxfilowxokbogygrigir4wqxfxqzuxofxgdon7dg6rsii4yxzytyd.onion", "http://searx.privpw3tndpkw6pnp3g727zfgfdzbu3k6a7chv226s3xymv2p4eiuqyd.onion", "http://rq2w52kyrif3xpfihkgjnhqm3a5aqhoikpv72z3drpjglfzc2wr5z4yd.onion", @@ -829,8 +749,21 @@ "i2p": [], "loki": [] }, + "breezeWiki": { + "clearnet": [ + "https://breezewiki.com", + "https://breezewiki.pussthecat.org", + "https://bw.odyssey346.dev", + "https://bw.vern.cc", + "https://breezewiki.esmailelbob.xyz" + ], + "tor": [], + "i2p": [], + "loki": [] + }, "peertube": [ "https://search.joinpeertube.org", + "https://freedomadultgames.video", "https://tbh.co-shaoghal.net", "https://tube.kansanvalta.org", "https://duanrra.cf", diff --git a/src/instances/get_instances.py b/src/instances/get_instances.py index 9fc64adc..fc730cf6 100644 --- a/src/instances/get_instances.py +++ b/src/instances/get_instances.py @@ -437,6 +437,10 @@ def libreTranslate(): fetchRegexList('libreTranslate', 'LibreTranslate', 'https://raw.githubusercontent.com/LibreTranslate/LibreTranslate/main/README.md', r"\[(?:[^\s\/]+\.)+[a-zA-Z0-9]+\]\((https?:\/{2}(?:[^\s\/]+\.)+[a-zA-Z0-9]+)\/?\)\|") +def breezeWiki(): + fetchRegexList('breezeWiki', 'BreezeWiki', 'https://gitdab.com/cadence/breezewiki-docs/raw/branch/main/docs.scrbl', r"\(\"[^\n\s\r\t\f\v\"]+\" \"https?:\/{2}(?:[^\s\/]+\.)+[a-zA-Z0-9]+(?:\/[^\s\/]+)*\" \"(https?:\/{2}(?:[^\s\/]+\.)+[a-zA-Z0-9]+(?:\/[^\s\/]+)*)\"\)") + + def peertube(): r = requests.get( 'https://instances.joinpeertube.org/api/v1/instances?start=0&count=1045&sort=-createdAt') @@ -485,6 +489,7 @@ beatbump() hyperpipe() facil() simpleertube() +breezeWiki() mightyList = filterLastSlash(mightyList) mightyList = idnaEncode(mightyList) diff --git a/src/pages/background/background.js b/src/pages/background/background.js index e8d0fd76..3f0e0fdd 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -30,11 +30,14 @@ browser.runtime.onInstalled.addListener(details => { .then(async data => { browser.storage.local.set({ blacklists: JSON.parse(data) }, async () => { switch (details.previousVersion) { + case "2.2.0": case "2.2.1": await generalHelper.initDefaults() await servicesHelper.initDefaults() await servicesHelper.upgradeOptions() break + default: + await servicesHelper.processUpdate() } }) }) diff --git a/src/pages/options/index.html b/src/pages/options/index.html index 323984ed..faeb5124 100644 --- a/src/pages/options/index.html +++ b/src/pages/options/index.html @@ -84,6 +84,11 @@ Reuters
+
+
+ + +
+ +
+
@@ -2200,6 +2212,114 @@
+ +
+
+

Fandom

+
+
+
+

Enable

+ +
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+ + +
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+
+
+

Default Instances

+
+
+
+
+

Custom Instances

+
+
+
+ + +
+
+
+
+ +
+
+

PeerTube

@@ -186,6 +191,11 @@

Reuters

+

PeerTube

-- cgit 1.4.1 From 375f4371c3c5e703b07ae3e3d677315134a035ce Mon Sep 17 00:00:00 2001 From: Hygna Date: Sun, 9 Oct 2022 13:11:05 +0100 Subject: Toggle current instance in popup Fixed bug where testing latency of multiple frontends at the same time wouldn't save all of the timings --- src/assets/images/instance-icon.svg | 3 + src/assets/javascripts/services.js | 4 +- src/assets/javascripts/utils.js | 17 ++-- src/config/config.json | 192 ++++++++++++++++++++++++++++-------- src/pages/background/background.js | 1 - src/pages/popup/popup.ejs | 6 ++ src/pages/popup/popup.html | 12 ++- src/pages/popup/popup.js | 31 +++++- src/pages/popup/style.css | 40 ++++++++ 9 files changed, 252 insertions(+), 54 deletions(-) create mode 100644 src/assets/images/instance-icon.svg (limited to 'src/pages/popup/popup.html') diff --git a/src/assets/images/instance-icon.svg b/src/assets/images/instance-icon.svg new file mode 100644 index 00000000..6b034c6f --- /dev/null +++ b/src/assets/images/instance-icon.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 80a1ac45..806624d7 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -422,7 +422,7 @@ function computeService(url, returnFrontend) { } else { for (const frontend in config.services[service].frontends) { if (all(service, frontend, options, config, redirects).includes(utils.protocolHost(url))) { - if (returnFrontend) resolve([service, frontend, url.hostname]) + if (returnFrontend) resolve([service, frontend, utils.protocolHost(url)]) else resolve(service) return } @@ -520,7 +520,7 @@ function unifyPreferences(url, tabId) { const frontendObject = config.services[service].frontends[frontend] if ("cookies" in frontendObject.preferences) { for (const cookie of frontendObject.preferences.cookies) { - utils.copyCookie(frontendObject, url, instancesList, cookie) + await utils.copyCookie(frontendObject, url, instancesList, cookie) } } if ("localstorage" in frontendObject.preferences) { diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js index 9ae9123f..62041690 100644 --- a/src/assets/javascripts/utils.js +++ b/src/assets/javascripts/utils.js @@ -424,17 +424,20 @@ function latency(service, frontend, document, location) { latencyElement.addEventListener("click", async () => { let reloadWindow = () => location.reload() latencyElement.addEventListener("click", reloadWindow) - browser.storage.local.get(["redirects", "latency"], r => { + browser.storage.local.get("redirects", r => { let redirects = r.redirects - let latency = r.latency const oldHtml = latencyLabel.innerHTML latencyLabel.innerHTML = "..." testLatency(latencyLabel, redirects[frontend].clearnet, frontend).then(r => { - latency[frontend] = r - browser.storage.local.set({ latency }) - latencyLabel.innerHTML = oldHtml - processDefaultCustomInstances(service, frontend, "clearnet", document) - latencyElement.removeEventListener("click", reloadWindow) + const frontendLatency = r + browser.storage.local.get("latency", r => { + let latency = r.latency + latency[frontend] = frontendLatency + browser.storage.local.set({ latency }) + latencyLabel.innerHTML = oldHtml + processDefaultCustomInstances(service, frontend, "clearnet", document) + latencyElement.removeEventListener("click", reloadWindow) + }) }) }) }) diff --git a/src/config/config.json b/src/config/config.json index ff4a869f..8110748f 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -22,8 +22,12 @@ "frontends": { "invidious": { "preferences": { - "cookies": ["PREFS"], - "localstorage": ["dark_mode"] + "cookies": [ + "PREFS" + ], + "localstorage": [ + "dark_mode" + ] }, "name": "Invidious", "embeddable": true, @@ -59,7 +63,9 @@ }, "pipedMaterial": { "preferences": { - "localstorage": ["PREFERENCES"] + "localstorage": [ + "PREFERENCES" + ] }, "name": "Piped-Material", "embeddable": false, @@ -109,7 +115,9 @@ "frontends": { "beatbump": { "preferences": { - "localstorage": ["settings"], + "localstorage": [ + "settings" + ], "indexeddb": "beatbump" }, "name": "Beatbump", @@ -117,14 +125,26 @@ }, "hyperpipe": { "preferences": { - "localstorage": ["api", "authapi", "codec", "locale", "next", "pipedapi", "quality", "theme", "vol"], + "localstorage": [ + "api", + "authapi", + "codec", + "locale", + "next", + "pipedapi", + "quality", + "theme", + "vol" + ], "indexeddb": "hyperpipedb" }, "name": "HyperPipe", "instanceList": true } }, - "targets": ["^https?:\\/{2}music\\.youtube\\.com(\\/.*|$)"], + "targets": [ + "^https?:\\/{2}music\\.youtube\\.com(\\/.*|$)" + ], "name": "YT Music", "options": { "enabled": true, @@ -139,24 +159,23 @@ "nitter": { "preferences": { "cookies": [ - "theme", - "infiniteScroll", - "stickyProfile", + "autoplayGifs", "bidiSupport", - "hideTweetStats", "hideBanner", "hidePins", "hideReplies", - "squareAvatars", - "mp4Playback", + "hideTweetStats", "hlsPlayback", - "proxyVideos", + "infiniteScroll", + "mp4Playback", "muteVideos", - "autoplayGifs", + "proxyVideos", "replaceInstagram", "replaceReddit", "replaceTwitter", - "replaceYouTube" + "replaceYouTube", + "squareAvatars", + "theme" ] }, "name": "Nitter", @@ -164,7 +183,12 @@ "instanceList": true } }, - "targets": ["^https?:\\/{2}(www\\.|mobile\\.|)twitter\\.com", "^https?:\\/{2}(pbs\\.|video\\.|)twimg\\.com", "^https?:\\/{2}platform\\.twitter\\.com/embed", "^https?:\\/{2}t\\.co"], + "targets": [ + "^https?:\\/{2}(www\\.|mobile\\.|)twitter\\.com", + "^https?:\\/{2}(pbs\\.|video\\.|)twimg\\.com", + "^https?:\\/{2}platform\\.twitter\\.com/embed", + "^https?:\\/{2}t\\.co" + ], "name": "Twitter", "options": { "enabled": true, @@ -186,7 +210,9 @@ "instanceList": true } }, - "targets": ["^https?:\\/{2}(www\\.)?instagram\\.com\\/p\\/"], + "targets": [ + "^https?:\\/{2}(www\\.)?instagram\\.com\\/p\\/" + ], "name": "Instagram", "options": { "enabled": true @@ -199,13 +225,18 @@ "frontends": { "proxiTok": { "preferences": { - "cookies": ["api-test_endpoints", "theme"] + "cookies": [ + "api-test_endpoints", + "theme" + ] }, "name": "ProxiTok", "instanceList": true } }, - "targets": ["^https?:\\/{2}(www\\.|)tiktok\\.com.*"], + "targets": [ + "^https?:\\/{2}(www\\.|)tiktok\\.com.*" + ], "name": "TikTok", "options": { "enabled": true @@ -218,7 +249,20 @@ "frontends": { "libreddit": { "preferences": { - "cookies": ["theme", "front_page", "layout", "wide", "post_sort", "comment_sort", "show_nsfw", "autoplay_videos", "use_hls", "hide_hls_notification", "subscriptions", "filters"] + "cookies": [ + "theme", + "front_page", + "layout", + "wide", + "post_sort", + "comment_sort", + "show_nsfw", + "autoplay_videos", + "use_hls", + "hide_hls_notification", + "subscriptions", + "filters" + ] }, "name": "Libreddit", "instanceList": true @@ -248,7 +292,10 @@ "instanceList": true } }, - "targets": ["^https?:\\/{2}(www\\.|old\\.|np\\.|new\\.|amp\\.|)reddit\\.com", "^https?:\\/{2}(i\\.|preview\\.)redd\\.it"], + "targets": [ + "^https?:\\/{2}(www\\.|old\\.|np\\.|new\\.|amp\\.|)reddit\\.com", + "^https?:\\/{2}(i\\.|preview\\.)redd\\.it" + ], "name": "Reddit", "options": { "enabled": true, @@ -266,7 +313,9 @@ "instanceList": true } }, - "targets": ["^https?:\\/{2}([im]\\.)?(stack\\.)?imgur\\.(com|io)(\\/|$)"], + "targets": [ + "^https?:\\/{2}([im]\\.)?(stack\\.)?imgur\\.(com|io)(\\/|$)" + ], "name": "Imgur", "options": { "enabled": true, @@ -280,13 +329,18 @@ "frontends": { "wikiless": { "preferences": { - "cookies": ["theme", "default_lang"] + "cookies": [ + "theme", + "default_lang" + ] }, "name": "Wikiless", "instanceList": true } }, - "targets": ["^https?:\\/{2}(?:[a-z]+\\.)*wikipedia\\.org"], + "targets": [ + "^https?:\\/{2}(?:[a-z]+\\.)*wikipedia\\.org" + ], "name": "Wikipedia", "options": { "enabled": false @@ -334,13 +388,17 @@ "frontends": { "quetre": { "preferences": { - "localstorage": ["theme"] + "localstorage": [ + "theme" + ] }, "name": "Quetre", "instanceList": true } }, - "targets": ["^https?:\\/{2}([a-z]+\\.)*quora\\.com.*"], + "targets": [ + "^https?:\\/{2}([a-z]+\\.)*quora\\.com.*" + ], "name": "Quora", "options": { "enabled": true @@ -353,13 +411,17 @@ "frontends": { "libremdb": { "preferences": { - "localstorage": ["theme"] + "localstorage": [ + "theme" + ] }, "name": "libremdb", "instanceList": true } }, - "targets": ["^https?:\\/{2}(?:www\\.|)imdb\\.com\\/title"], + "targets": [ + "^https?:\\/{2}(?:www\\.|)imdb\\.com\\/title" + ], "name": "IMDb", "options": { "enabled": true @@ -375,7 +437,9 @@ "instanceList": true } }, - "targets": ["^https?:\\/{2}(www\\.|)reuters\\.com.*"], + "targets": [ + "^https?:\\/{2}(www\\.|)reuters\\.com.*" + ], "name": "Reuters", "options": { "enabled": false @@ -391,7 +455,9 @@ "instanceList": true } }, - "targets": ["^https?:\\/{2}(?:[a-zA-Z0-9]+\\.)?fandom\\.com(?=(?:\\/wiki)|(?:\\/?$))"], + "targets": [ + "^https?:\\/{2}(?:[a-zA-Z0-9]+\\.)?fandom\\.com(?=(?:\\/wiki)|(?:\\/?$))" + ], "name": "Fandom", "options": { "enabled": true @@ -420,8 +486,18 @@ "frontends": { "librarian": { "preferences": { - "cookies": ["nsfw", "theme"], - "localstorage": ["autoplay", "autoplayNextVid", "collapseComments", "plyr", "sb_categories", "showRelated"] + "cookies": [ + "nsfw", + "theme" + ], + "localstorage": [ + "autoplay", + "autoplayNextVid", + "collapseComments", + "plyr", + "sb_categories", + "showRelated" + ] }, "name": "Librarian", "embeddable": true, @@ -433,7 +509,10 @@ "instanceList": false } }, - "targets": ["^https?:\\/{2}odysee\\.com", "^https?:\\/{2}lbry\\.tv"], + "targets": [ + "^https?:\\/{2}odysee\\.com", + "^https?:\\/{2}lbry\\.tv" + ], "name": "LBRY", "options": { "enabled": true, @@ -506,13 +585,26 @@ }, "librex": { "preferences": { - "cookies": ["bibliogram", "disable_frontends", " disable_special", "invidious", "libreddit", "nitter", "proxitok", "save", "theme", "wikiless"] + "cookies": [ + "bibliogram", + "disable_frontends", + " disable_special", + "invidious", + "libreddit", + "nitter", + "proxitok", + "save", + "theme", + "wikiless" + ] }, "name": "LibreX", "instanceList": true } }, - "targets": ["^https?:\\/{2}search\\.libredirect\\.invalid"], + "targets": [ + "^https?:\\/{2}search\\.libredirect\\.invalid" + ], "name": "Search", "options": { "enabled": true, @@ -526,14 +618,24 @@ "frontends": { "simplyTranslate": { "preferences": { - "cookies": ["from_lang", "to_lang", "tts_enabled", "use_text_fields"] + "cookies": [ + "from_lang", + "to_lang", + "tts_enabled", + "use_text_fields" + ] }, "name": "SimplyTranslate", "instanceList": true }, "lingva": { "preferences": { - "localstorage": ["isauto", "source", "target", "chakra-ui-color-mode"] + "localstorage": [ + "isauto", + "source", + "target", + "chakra-ui-color-mode" + ] }, "name": "Lingva Translate", "instanceList": true @@ -543,7 +645,10 @@ "instanceList": true } }, - "targets": ["^https?:\\/{2}translate\\.google(\\.[a-z]{2,3}){1,2}\\/", "^https?:\\/{2}translate\\.libredirect\\.invalid"], + "targets": [ + "^https?:\\/{2}translate\\.google(\\.[a-z]{2,3}){1,2}\\/", + "^https?:\\/{2}translate\\.libredirect\\.invalid" + ], "name": "Translate", "options": { "enabled": true, @@ -565,7 +670,10 @@ "singleInstance": "https://www.openstreetmap.org" } }, - "targets": ["^https?:\\/{2}maps\\.libredirect\\.invalid", "^https?:\\/{2}(((www|maps)\\.)?(google\\.).*(\\/maps)|maps\\.(google\\.).*)"], + "targets": [ + "^https?:\\/{2}maps\\.libredirect\\.invalid", + "^https?:\\/{2}(((www|maps)\\.)?(google\\.).*(\\/maps)|maps\\.(google\\.).*)" + ], "name": "Maps", "options": { "enabled": true, @@ -582,7 +690,11 @@ "instanceList": "true" } }, - "targets": ["^https?:\\/{2}send\\.libredirect\\.invalid", "^https?:\\/{2}send\\.firefox\\.com\\/?$", "^https?:\\/{2}sendfiles\\.online\\/?$"], + "targets": [ + "^https?:\\/{2}send\\.libredirect\\.invalid", + "^https?:\\/{2}send\\.firefox\\.com\\/?$", + "^https?:\\/{2}sendfiles\\.online\\/?$" + ], "name": "Send Files", "options": { "enabled": true diff --git a/src/pages/background/background.js b/src/pages/background/background.js index d252e580..dd8f1715 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -232,7 +232,6 @@ browser.contextMenus.onClicked.addListener((info, tab) => { } } case "redirectLink": - console.log(info.linkUrl) const tmpUrl = new URL(info.linkUrl) const newUrl = servicesHelper.redirect(tmpUrl, "main_frame", null, true) if (newUrl) browser.tabs.create({ url: newUrl }) diff --git a/src/pages/popup/popup.ejs b/src/pages/popup/popup.ejs index e862e0cb..e6cc6fca 100644 --- a/src/pages/popup/popup.ejs +++ b/src/pages/popup/popup.ejs @@ -8,6 +8,12 @@
+ <%- include('src/pages/widgets/switches', {services: services}) -%>

diff --git a/src/pages/popup/popup.html b/src/pages/popup/popup.html index 2dcc12bc..6dc48478 100644 --- a/src/pages/popup/popup.html +++ b/src/pages/popup/popup.html @@ -8,6 +8,14 @@
+

Youtube

@@ -78,7 +86,7 @@

Fandom

-
+

PeerTube

@@ -196,7 +204,7 @@

Fandom

-
+

PeerTube

diff --git a/src/pages/popup/popup.js b/src/pages/popup/popup.js index a4b73093..78e50004 100644 --- a/src/pages/popup/popup.js +++ b/src/pages/popup/popup.js @@ -2,7 +2,6 @@ window.browser = window.browser || window.chrome import utils from "../../assets/javascripts/utils.js" -// import generalHelper from "../../assets/javascripts/general.js" import serviceHelper from "../../assets/javascripts/services.js" let config, @@ -40,6 +39,7 @@ const currSite = document.getElementsByClassName("current_site")[0] function setDivs() { return new Promise(resolve => { + divs.instance = document.getElementById("instance") for (const service in config.services) { divs[service] = {} divs[service].toggle = {} @@ -56,8 +56,9 @@ await setDivs() const currentSiteIsFrontend = document.getElementById("current_site_divider") -browser.storage.local.get("options", r => { +browser.storage.local.get(["options", "redirects"], r => { browser.tabs.query({ active: true, currentWindow: true }, async tabs => { + document.getElementById("instance-div").classList.add("hide") for (const service in config.services) { if (!r.options.popupServices.includes(service)) allSites.getElementsByClassName(service)[0].classList.add("hide") else allSites.getElementsByClassName(service)[0].classList.remove("hide") @@ -80,10 +81,36 @@ browser.storage.local.get("options", r => { let service = await serviceHelper.computeService(url, true) let frontend + let instance if (service) { if (typeof service != "string") { + instance = service[2] frontend = service[1] service = service[0] + divs.instance.innerHTML = instance.replace(/https?:\/{2}/, "") + let tmp + let instanceNetwork + for (const network in config.networks) { + tmp = r.redirects[frontend][network].indexOf(instance) + if (tmp > -1) { + const instanceDiv = document.getElementById("instance-enabled") + tmp = r.options[frontend][network].enabled.indexOf(instance) + if (tmp > -1) instanceDiv.checked = true + else instanceDiv.checked = false + instanceNetwork = network + instanceDiv.addEventListener("change", () => { + browser.storage.local.get("options", r => { + // Although options would be avaliable in this context, it is fetched again to make sure it is up to date + let options = r.options + if (instanceDiv.checked) options[frontend][instanceNetwork].enabled.push(instance) + else options[frontend][instanceNetwork].enabled.splice(options[frontend][instanceNetwork].enabled.indexOf(instance), 1) + browser.storage.local.set({ options }) + }) + }) + break + } + } + document.getElementById("instance-div").classList.remove("hide") } divs[service].current.classList.remove("hide") divs[service].all.classList.add("hide") diff --git a/src/pages/popup/style.css b/src/pages/popup/style.css index 0cb27912..3b409be8 100644 --- a/src/pages/popup/style.css +++ b/src/pages/popup/style.css @@ -22,3 +22,43 @@ body { .space { height: 10px; } + +input { + height: 23px; + width: 46px; +} + +#instance { + max-width: 110px; + max-height: 22px; + overflow-x: scroll; + white-space: nowrap; + scrollbar-width: none; + -ms-overflow-style: none; +} + +#instance::-webkit-scrollbar { + display: none; +} + +#instance::before { + background-image: linear-gradient(to right, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0)); + position: absolute; + width: 5px; + height: 22px; + content: ""; + display: block; + pointer-events: none; +} + +#end::before { + background-image: linear-gradient(to left, rgba(0, 0, 0, 1), rgba(0, 0, 0, 0)); + position: absolute; + width: 5px; + height: 22px; + content: ""; + display: block; + pointer-events: none; + top: 13px; + left: 157.4px; +} -- cgit 1.4.1