From 0803eb5e0484920f31e994303fd2bb07d6f5ec83 Mon Sep 17 00:00:00 2001 From: BobIsMyManager Date: Wed, 27 Jul 2022 11:05:49 +0100 Subject: Added lbry desktop Closes https://github.com/libredirect/libredirect/issues/365 --- src/_locales/en/messages.json | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/_locales/en') diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index dfbede1a..23d42e48 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -207,5 +207,8 @@ }, "protocolFallback": { "message": "Fallback to normal if no instances are available for the current protocol" + }, + "lbryDesktop": { + "message": "LBRY Desktop" } } -- cgit 1.4.1 From 416a4ee13c61dea24adb52a3f3477ec230a38bed Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Sun, 14 Aug 2022 14:05:16 +0300 Subject: Fixed typo https://github.com/libredirect/libredirect/issues/408 --- src/_locales/ar/messages.json | 2 +- src/_locales/de/messages.json | 2 +- src/_locales/en/messages.json | 2 +- src/_locales/es/messages.json | 2 +- src/_locales/fr/messages.json | 2 +- src/_locales/gl/messages.json | 2 +- src/_locales/id/messages.json | 2 +- src/_locales/it/messages.json | 2 +- src/_locales/ja/messages.json | 2 +- src/_locales/ko/messages.json | 2 +- src/_locales/nb_NO/messages.json | 2 +- src/_locales/nl/messages.json | 2 +- src/_locales/pl/messages.json | 2 +- src/_locales/pt_BR/messages.json | 2 +- src/_locales/ru/messages.json | 2 +- src/_locales/tr/messages.json | 2 +- src/pages/errors/instance_offline.html | 5 +++-- 17 files changed, 19 insertions(+), 18 deletions(-) (limited to 'src/_locales/en') diff --git a/src/_locales/ar/messages.json b/src/_locales/ar/messages.json index 4874ef15..86534b00 100644 --- a/src/_locales/ar/messages.json +++ b/src/_locales/ar/messages.json @@ -161,7 +161,7 @@ "description": "used in the settings page" }, "instanceOffline": { - "message": "هذا النظير غير متصل بالإنترنت، سيتم إعادة توجيهك بعد ", + "message": "هذا النظير غير متصل بالإنترنت، سيتم إعادة توجيهك بعد", "description": "used in instance_offline.html" }, "cancel": { diff --git a/src/_locales/de/messages.json b/src/_locales/de/messages.json index 55bb0dc4..892918d3 100644 --- a/src/_locales/de/messages.json +++ b/src/_locales/de/messages.json @@ -206,7 +206,7 @@ "message": "I2P" }, "instanceOffline": { - "message": "Diese Instanz ist offline , du wirst weitergeleitet nach  " + "message": "Diese Instanz ist offline , du wirst weitergeleitet nach " }, "testInstancesLatency": { "message": "Teste Latenz der Instanzen" diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 23d42e48..d4217ad9 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -175,7 +175,7 @@ "description": "used in the settings page" }, "instanceOffline": { - "message": "This instance is offline, you'll be redirected after ", + "message": "This instance is offline, you'll be redirected after", "description": "used in instance_offline.html" }, "cancel": { diff --git a/src/_locales/es/messages.json b/src/_locales/es/messages.json index 07ea98c3..1998e799 100644 --- a/src/_locales/es/messages.json +++ b/src/_locales/es/messages.json @@ -107,7 +107,7 @@ "message": "I2P" }, "instanceOffline": { - "message": "Esta instancia está offline, serás redirigido/a luego de ", + "message": "Esta instancia está offline, serás redirigido/a luego de", "description": "used in instance_offline.html" }, "testInstancesLatency": { diff --git a/src/_locales/fr/messages.json b/src/_locales/fr/messages.json index c3234890..717ec8e1 100644 --- a/src/_locales/fr/messages.json +++ b/src/_locales/fr/messages.json @@ -139,7 +139,7 @@ "description": "used in the settings page" }, "instanceOffline": { - "message": "Cette instance est hors ligne, vous serez redirigé après ", + "message": "Cette instance est hors ligne, vous serez redirigé après", "description": "used in instance_offline.html" }, "settings": { diff --git a/src/_locales/gl/messages.json b/src/_locales/gl/messages.json index fba02255..a88810f6 100644 --- a/src/_locales/gl/messages.json +++ b/src/_locales/gl/messages.json @@ -196,7 +196,7 @@ "message": "Esta interface non é totalmente privada." }, "instanceOffline": { - "message": "Esta instancia está caída, ímoste redirixir após ", + "message": "Esta instancia está caída, ímoste redirixir após", "description": "used in instance_offline.html" }, "cancel": { diff --git a/src/_locales/id/messages.json b/src/_locales/id/messages.json index 5e4d2b16..09ab8fe4 100644 --- a/src/_locales/id/messages.json +++ b/src/_locales/id/messages.json @@ -127,7 +127,7 @@ "description": "used in the settings page" }, "instanceOffline": { - "message": "Instansi ini luring, Anda akan dialihkan setelah ", + "message": "Instansi ini luring, Anda akan dialihkan setelah", "description": "used in instance_offline.html" }, "cancel": { diff --git a/src/_locales/it/messages.json b/src/_locales/it/messages.json index 9370f1a9..eab2d038 100644 --- a/src/_locales/it/messages.json +++ b/src/_locales/it/messages.json @@ -159,7 +159,7 @@ "description": "used in the settings page" }, "instanceOffline": { - "message": "Questa istanza è offline, verrai reindirizzato tra ", + "message": "Questa istanza è offline, verrai reindirizzato tra", "description": "used in instance_offline.html" }, "cancel": { diff --git a/src/_locales/ja/messages.json b/src/_locales/ja/messages.json index 32407e8d..bfae80c9 100644 --- a/src/_locales/ja/messages.json +++ b/src/_locales/ja/messages.json @@ -179,7 +179,7 @@ "description": "used in the settings page" }, "instanceOffline": { - "message": "このインスタンスはオフラインです。 ", + "message": "このインスタンスはオフラインです。", "description": "used in instance_offline.html" }, "cancel": { diff --git a/src/_locales/ko/messages.json b/src/_locales/ko/messages.json index ad48864c..53cfcc13 100644 --- a/src/_locales/ko/messages.json +++ b/src/_locales/ko/messages.json @@ -115,7 +115,7 @@ "description": "used in the settings page" }, "instanceOffline": { - "message": "이 인스턴스는 오프라인입니다, 다음 초 후에 리다이렉트됩니다: ", + "message": "이 인스턴스는 오프라인입니다, 다음 초 후에 리다이렉트됩니다:", "description": "used in instance_offline.html" }, "notFullyPrivate": { diff --git a/src/_locales/nb_NO/messages.json b/src/_locales/nb_NO/messages.json index 9a18930f..adae7e51 100644 --- a/src/_locales/nb_NO/messages.json +++ b/src/_locales/nb_NO/messages.json @@ -168,7 +168,7 @@ "description": "used in the settings page" }, "instanceOffline": { - "message": "Denne instansen er nede. Du vil bli videresendt etter ", + "message": "Denne instansen er nede. Du vil bli videresendt etter", "description": "used in instance_offline.html" }, "copyRaw": { diff --git a/src/_locales/nl/messages.json b/src/_locales/nl/messages.json index fa223f60..e1c1ea17 100644 --- a/src/_locales/nl/messages.json +++ b/src/_locales/nl/messages.json @@ -173,7 +173,7 @@ "description": "used in the settings page" }, "instanceOffline": { - "message": "Deze server is offline - je wordt doorgestuurd over ", + "message": "Deze server is offline - je wordt doorgestuurd over", "description": "used in instance_offline.html" }, "cancel": { diff --git a/src/_locales/pl/messages.json b/src/_locales/pl/messages.json index 8ee06cc0..aed2eda5 100644 --- a/src/_locales/pl/messages.json +++ b/src/_locales/pl/messages.json @@ -100,7 +100,7 @@ "description": "used in the settings page" }, "instanceOffline": { - "message": "Ta instancja jest offline, przekierowanie nastąpi po ", + "message": "Ta instancja jest offline, przekierowanie nastąpi po", "description": "used in instance_offline.html" }, "cancel": { diff --git a/src/_locales/pt_BR/messages.json b/src/_locales/pt_BR/messages.json index 53b1de52..72729117 100644 --- a/src/_locales/pt_BR/messages.json +++ b/src/_locales/pt_BR/messages.json @@ -181,7 +181,7 @@ "description": "used in the settings page" }, "instanceOffline": { - "message": "Esta instância está offline, você será redirecionado após ", + "message": "Esta instância está offline, você será redirecionado após", "description": "used in instance_offline.html" }, "instanceIsOff": { diff --git a/src/_locales/ru/messages.json b/src/_locales/ru/messages.json index 04afb07a..f48150fe 100644 --- a/src/_locales/ru/messages.json +++ b/src/_locales/ru/messages.json @@ -96,7 +96,7 @@ "description": "used in the settings page" }, "instanceOffline": { - "message": "Этот экземпляр находится в автономном режиме, вы будете перенаправлены после ", + "message": "Этот экземпляр находится в автономном режиме, вы будете перенаправлены после", "description": "used in instance_offline.html" }, "cancel": { diff --git a/src/_locales/tr/messages.json b/src/_locales/tr/messages.json index 8763af8f..fe434073 100644 --- a/src/_locales/tr/messages.json +++ b/src/_locales/tr/messages.json @@ -119,7 +119,7 @@ "description": "used in the settings page" }, "instanceOffline": { - "message": "Bu örnek çevrim dışı, yeniden yönlendirileceksiniz ", + "message": "Bu örnek çevrim dışı, yeniden yönlendirileceksiniz", "description": "used in instance_offline.html" }, "cancel": { diff --git a/src/pages/errors/instance_offline.html b/src/pages/errors/instance_offline.html index 4f27445c..a74caec2 100644 --- a/src/pages/errors/instance_offline.html +++ b/src/pages/errors/instance_offline.html @@ -27,8 +27,9 @@
-

- This instance is offline, you'll be redirected after 2 seconds +

+ This instance is offline, you'll be redirected after + 2 seconds

-- cgit 1.4.1 From be78f86a67458208279b8cb51b2c6fab4491244c Mon Sep 17 00:00:00 2001 From: Hygna Date: Sat, 8 Oct 2022 11:37:45 +0100 Subject: Added context menu to toggle redirects for a certain tab Closes https://github.com/libredirect/libredirect/issues/464 --- src/_locales/en/messages.json | 4 +++ src/assets/javascripts/services.js | 28 +++++++++------- src/pages/background/background.js | 67 +++++++++++++++++++++++++------------- 3 files changed, 65 insertions(+), 34 deletions(-) (limited to 'src/_locales/en') diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index d4217ad9..003a878e 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -210,5 +210,9 @@ }, "lbryDesktop": { "message": "LBRY Desktop" + }, + "bypassTab": { + "message": "Toggle redirects in this tab", + "description": "Used in context menus when right clicking on a page/tab" } } diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index a102a297..7e0a76a4 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -68,13 +68,14 @@ function redirect(url, type, initiator) { if (!options[service].enabled) continue if (config.services[service].embeddable && type != options[service].redirectType && options[service].redirectType != "both") continue if (!config.services[service].embeddable && type != "main_frame") continue - let targets = new RegExp(config.services[service].targets.join("|"), "i") + // let targets = new RegExp(config.services[service].targets.join("|"), "i") if (!regexArray(service, url, config)) continue - if (initiator) { - if (targets.test(initiator.host)) continue - if (all(service, null, options, config, redirects).includes(initiator.origin) && reverse(initiator) == url) return "BYPASSTAB" - } + // if (initiator) { + // console.log(initiator.host) + // if (targets.test(initiator.host)) continue + // //if (all(service, null, options, config, redirects).includes(initiator.origin) && reverse(initiator) == url) return "BYPASSTAB" + // } if (Object.keys(config.services[service].frontends).length > 1) { if (type == "sub_frame" && config.services[service].embeddable && !config.services[service].frontends[options[service].frontend].embeddable) frontend = options[service].embedFrontend @@ -473,26 +474,29 @@ function switchInstance(url) { }) } -function reverse(url) { +function reverse(url, urlString) { return new Promise(async resolve => { await init() - let protocolHost = utils.protocolHost(url) + let protocolHost + if (!urlString) protocolHost = utils.protocolHost(url) + else protocolHost = url.match(/https?:\/{2}(?:[^\s\/]+\.)+[a-zA-Z0-9]+/)[0] 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) + case "imdb": + case "reuters": + case "quora": + case "medium": + if (!urlString) resolve(config.services[service].url + url.pathname + url.search) + else resolve(url.replace(/https?:\/{2}(?:[^\s\/]+\.)+[a-zA-Z0-9]+/, config.services[service].url)) return default: resolve() diff --git a/src/pages/background/background.js b/src/pages/background/background.js index 3f0e0fdd..f53d7b97 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -69,11 +69,11 @@ browser.webRequest.onBeforeRequest.addListener( console.log(`Canceled ${url}`) return { cancel: true } } - if (newUrl === "BYPASSTAB") { - console.log(`Bypassed ${details.tabId} ${url}`) - if (!BYPASSTABs.includes(details.tabId)) BYPASSTABs.push(details.tabId) - return null - } + // if (newUrl === "BYPASSTAB") { + // console.log(`Bypassed ${details.tabId} ${url}`) + // if (!BYPASSTABs.includes(details.tabId)) BYPASSTABs.push(details.tabId) + // return null + // } console.info("Redirecting", url.href, "=>", newUrl) return { redirectUrl: newUrl } } @@ -91,18 +91,6 @@ browser.tabs.onRemoved.addListener(tabId => { } }) -/* -browser.webRequest.onHeadersReceived.addListener( - e => { - let response = youtubeHelper.removeXFrameOptions(e) - if (!response) response = twitterHelper.removeXFrameOptions(e) - return response - }, - { urls: [""] }, - ["blocking", "responseHeaders"] -) -*/ - async function redirectOfflineInstance(url, tabId) { let newUrl = await servicesHelper.switchInstance(url, true) @@ -170,11 +158,46 @@ browser.contextMenus.create({ contexts: ["browser_action"], }) -browser.contextMenus.onClicked.addListener(info => { - if (info.menuItemId == "switchInstance") utils.switchInstance() - else if (info.menuItemId == "settings") browser.runtime.openOptionsPage() - else if (info.menuItemId == "copyRaw") utils.copyRaw() - else if (info.menuItemId == "unify") utils.unify() +browser.contextMenus.create({ + id: "bypassTab", + title: browser.i18n.getMessage("bypassTab"), + contexts: ["page", "tab"], +}) + +browser.contextMenus.onClicked.addListener((info, tab) => { + return new Promise(async resolve => { + switch (info.menuItemId) { + case "switchInstance": + utils.switchInstance() + resolve() + return + case "settings": + browser.runtime.openOptionsPage() + resolve() + return + case "copyRaw": + utils.copyRaw() + resolve() + return + case "unify": + utils.unify() + resolve() + return + case "bypassTab": + if (!BYPASSTABs.includes(tab.id)) { + BYPASSTABs.push(tab.id) + let newUrl = await servicesHelper.reverse(tab.url, true) + if (newUrl) browser.tabs.update(tab.id, { url: newUrl }) + resolve() + return + } else { + BYPASSTABs.splice(BYPASSTABs.indexOf(tab.id), 1) + browser.tabs.reload(tab.id) + resolve() + return + } + } + }) }) browser.runtime.onMessage.addListener((message, sender, sendResponse) => { -- cgit 1.4.1 From 9560cfc3e793d9fcb4fd8184c3d83fc0f4958f67 Mon Sep 17 00:00:00 2001 From: Hygna Date: Sat, 8 Oct 2022 16:33:39 +0100 Subject: Fixed bugs present in the previous commit --- src/_locales/en/messages.json | 2 +- src/assets/javascripts/services.js | 5 +- src/config/config.json | 61 ++++++++++++++++++------ src/pages/background/background.js | 82 ++++++++++++++++++++++++--------- src/pages/background/reset_warning.html | 59 ------------------------ src/pages/background/reset_warning.js | 7 --- src/pages/stylesheets/styles.css | 5 ++ 7 files changed, 114 insertions(+), 107 deletions(-) delete mode 100644 src/pages/background/reset_warning.html delete mode 100644 src/pages/background/reset_warning.js (limited to 'src/_locales/en') diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index 003a878e..b8dccda3 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -211,7 +211,7 @@ "lbryDesktop": { "message": "LBRY Desktop" }, - "bypassTab": { + "toggleTab": { "message": "Toggle redirects in this tab", "description": "Used in context menus when right clicking on a page/tab" } diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 7e0a76a4..6614bf92 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -60,12 +60,12 @@ function regexArray(service, url, config) { return false } -function redirect(url, type, initiator) { +function redirect(url, type, initiator, forceRedirection) { if (type != "main_frame" && type != "sub_frame") return let randomInstance let frontend for (const service in config.services) { - if (!options[service].enabled) continue + if (!forceRedirection && !options[service].enabled) continue if (config.services[service].embeddable && type != options[service].redirectType && options[service].redirectType != "both") continue if (!config.services[service].embeddable && type != "main_frame") continue // let targets = new RegExp(config.services[service].targets.join("|"), "i") @@ -407,6 +407,7 @@ function redirect(url, type, initiator) { } function computeService(url, returnFrontend) { + console.log(url) return new Promise(resolve => { fetch("/config/config.json") .then(response => response.text()) diff --git a/src/config/config.json b/src/config/config.json index 97168263..642d90ee 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -188,7 +188,9 @@ }, "targets": ["^https?:\\/{2}(www\\.)?instagram\\.com\\/p\\/"], "name": "Instagram", - "options": { "enabled": true }, + "options": { + "enabled": true + }, "imageType": "png", "embeddable": false, "url": "https://instagram.com" @@ -205,7 +207,9 @@ }, "targets": ["^https?:\\/{2}(www\\.|)tiktok\\.com.*"], "name": "TikTok", - "options": { "enabled": true }, + "options": { + "enabled": true + }, "imageType": "png", "embeddable": false, "url": "https://tiktok.com" @@ -223,6 +227,7 @@ "preferences": { "cookies": [ "collapse_child_comments", + "default_comment_sort", "domain_instagram", "domain_twitter", "domain_youtube", @@ -230,8 +235,11 @@ "highlight_controversial", "nsfw_enabled", "post_media_max_height", + "prefer_frontpage", + "show_large_gallery_images", "show_upvoted_percentage", "show_upvotes", + "subbed_subreddits", "theme", "videos_muted" ] @@ -280,7 +288,9 @@ }, "targets": ["^https?:\\/{2}(?:[a-z]+\\.)*wikipedia\\.org"], "name": "Wikipedia", - "options": { "enabled": false }, + "options": { + "enabled": false + }, "imageType": "svg", "embeddable": false, "url": "https://wikipedia.org" @@ -313,7 +323,9 @@ "^writingcooperative\\.com" ], "name": "Medium", - "options": { "enabled": true }, + "options": { + "enabled": true + }, "imageType": "svgMono", "embeddable": false, "url": "https://medium.com" @@ -330,7 +342,9 @@ }, "targets": ["^https?:\\/{2}([a-z]+\\.)*quora\\.com.*"], "name": "Quora", - "options": { "enabled": true }, + "options": { + "enabled": true + }, "imageType": "png", "embeddable": false, "url": "https://quora.com" @@ -345,9 +359,11 @@ "instanceList": true } }, - "targets": ["^https?:\\/{2}(?:www\\.|)imdb\\.com.*"], + "targets": ["^https?:\\/{2}(?:www\\.|)imdb\\.com\\/title"], "name": "IMDb", - "options": { "enabled": false }, + "options": { + "enabled": true + }, "imageType": "svg", "embeddable": false, "url": "https://imdb.com" @@ -361,7 +377,9 @@ }, "targets": ["^https?:\\/{2}(www\\.|)reuters\\.com.*"], "name": "Reuters", - "options": { "enabled": false }, + "options": { + "enabled": false + }, "imageType": "svg", "embeddable": false, "url": "https://reuters.com" @@ -375,7 +393,9 @@ }, "targets": ["^https?:\\/{2}(?:[a-zA-Z0-9]+\\.)?fandom\\.com(?=(?:\\/wiki)|(?:\\/?$))"], "name": "Fandom", - "options": { "enabled": true }, + "options": { + "enabled": true + }, "imageType": "svg", "embeddable": false, "url": "https://fandom.com" @@ -389,7 +409,9 @@ }, "targets": "datajson", "name": "PeerTube", - "options": { "enabled": false }, + "options": { + "enabled": false + }, "imageType": "svg", "embeddable": false, "url": "https://search.joinpeertube.org" @@ -414,7 +436,7 @@ "targets": ["^https?:\\/{2}odysee\\.com", "^https?:\\/{2}lbry\\.tv"], "name": "LBRY", "options": { - "enabled": false, + "enabled": true, "frontend": "librarian", "redirectType": "both", "embedFrontend": "librarian" @@ -455,6 +477,7 @@ "cookies": [ "autocomplete", "categories", + "center_alignment", "disabled_engines", "disabled_plugins", "doi_resolver", @@ -561,15 +584,23 @@ }, "targets": ["^https?:\\/{2}send\\.libredirect\\.invalid", "^https?:\\/{2}send\\.firefox\\.com\\/?$", "^https?:\\/{2}sendfiles\\.online\\/?$"], "name": "Send Files", - "options": { "enabled": true }, + "options": { + "enabled": true + }, "imageType": "svgMono", "embeddable": false, "url": "https://send.libredirect.invalid" } }, "blacklist": { - "cloudflare": { "color": "red" }, - "authenticate": { "color": "orange" }, - "offline": { "color": "grey" } + "cloudflare": { + "color": "red" + }, + "authenticate": { + "color": "orange" + }, + "offline": { + "color": "grey" + } } } diff --git a/src/pages/background/background.js b/src/pages/background/background.js index f53d7b97..54a80011 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -20,6 +20,7 @@ function initDefaults() { } browser.runtime.onInstalled.addListener(details => { + if (details.previousVersion != browser.runtime.getManifest().version) { switch (details.reason) { case "install": initDefaults() @@ -42,9 +43,11 @@ browser.runtime.onInstalled.addListener(details => { }) }) } + } }) -let BYPASSTABs = [] +let tabIdRedirects = {} +// true == Always redirect, false == Never redirect, null/undefined == follow options for services browser.webRequest.onBeforeRequest.addListener( details => { const url = new URL(details.url) @@ -57,23 +60,23 @@ browser.webRequest.onBeforeRequest.addListener( return null } - let newUrl = servicesHelper.redirect(url, details.type, initiator) + if (tabIdRedirects[details.tabId] == false) return null + let newUrl = servicesHelper.redirect(url, details.type, initiator, tabIdRedirects[details.tabId]) if (details.frameAncestors && details.frameAncestors.length > 0 && generalHelper.isException(new URL(details.frameAncestors[0].url))) newUrl = null if (generalHelper.isException(url)) newUrl = "BYPASSTAB" - if (BYPASSTABs.includes(details.tabId)) newUrl = null if (newUrl) { if (newUrl === "CANCEL") { console.log(`Canceled ${url}`) return { cancel: true } } - // if (newUrl === "BYPASSTAB") { - // console.log(`Bypassed ${details.tabId} ${url}`) - // if (!BYPASSTABs.includes(details.tabId)) BYPASSTABs.push(details.tabId) - // return null - // } + if (newUrl === "BYPASSTAB") { + console.log(`Bypassed ${details.tabId} ${url}`) + if (tabIdRedirects[details.tabId] != false) tabIdRedirects[details.tabId] = false + return null + } console.info("Redirecting", url.href, "=>", newUrl) return { redirectUrl: newUrl } } @@ -84,10 +87,9 @@ browser.webRequest.onBeforeRequest.addListener( ) browser.tabs.onRemoved.addListener(tabId => { - const i = BYPASSTABs.indexOf(tabId) - if (i > -1) { - BYPASSTABs.splice(i, 1) - console.log("Removed BYPASSTABs", tabId) + if (tabIdRedirects[tabId] != undefined) { + delete tabIdRedirects[tabId] + console.log("Removed tab " + tabId + " from tabIdRedirects") } }) @@ -159,11 +161,30 @@ browser.contextMenus.create({ }) browser.contextMenus.create({ - id: "bypassTab", - title: browser.i18n.getMessage("bypassTab"), + id: "toggleTab", + title: browser.i18n.getMessage("toggleTab"), contexts: ["page", "tab"], }) +function handleToggleTab(tab) { + return new Promise(async resolve => { + console.log(tabIdRedirects[tab.id]) + switch (tabIdRedirects[tab.id]) { + case false: + console.log("kj") + const newUrl = await servicesHelper.reverse(tab.url, true) + if (newUrl) browser.tabs.update(tab.id, { url: newUrl }) + resolve() + return + case true: + console.log("lsad") + browser.tabs.reload(tab.id) + resolve() + return + } + }) +} + browser.contextMenus.onClicked.addListener((info, tab) => { return new Promise(async resolve => { switch (info.menuItemId) { @@ -183,18 +204,33 @@ browser.contextMenus.onClicked.addListener((info, tab) => { utils.unify() resolve() return - case "bypassTab": - if (!BYPASSTABs.includes(tab.id)) { - BYPASSTABs.push(tab.id) - let newUrl = await servicesHelper.reverse(tab.url, true) - if (newUrl) browser.tabs.update(tab.id, { url: newUrl }) + case "toggleTab": + if (tabIdRedirects[tab.id] != undefined) { + tabIdRedirects[tab.id] = !tabIdRedirects[tab.id] + await handleToggleTab(tab) resolve() return } else { - BYPASSTABs.splice(BYPASSTABs.indexOf(tab.id), 1) - browser.tabs.reload(tab.id) - resolve() - return + console.log("n") + const url = new URL(tab.url) + const service = await servicesHelper.computeService(url) + console.log(service) + if (service) { + console.log("h") + browser.storage.local.get("options", async r => { + console.log(r.options[service]) + if (r.options[service].enabled) tabIdRedirects[tab.id] = false + else tabIdRedirects[tab.id] = true + await handleToggleTab(tab) + resolve() + return + }) + } else { + tabIdRedirects[tab.id] = false + await handleToggleTab(tab) + resolve() + return + } } } }) diff --git a/src/pages/background/reset_warning.html b/src/pages/background/reset_warning.html deleted file mode 100644 index f1881ed8..00000000 --- a/src/pages/background/reset_warning.html +++ /dev/null @@ -1,59 +0,0 @@ - - - - - - - Reset Warning - - - - - -
- - -

All settings have been reset as they're incompatible with the previous version.

-

Sorry for the inconvenience, but we're going in a fast development process and can't support nor convert older settings. It will reach a stable plateau though.

- - - - - -   - Export Settings - -
- - - diff --git a/src/pages/background/reset_warning.js b/src/pages/background/reset_warning.js deleted file mode 100644 index 9ce49c9a..00000000 --- a/src/pages/background/reset_warning.js +++ /dev/null @@ -1,7 +0,0 @@ -let params = new URLSearchParams(location.search) - -const resultString = JSON.stringify(JSON.parse(params.get("data")), null, " ") - -let exportSettingsElement = document.getElementById("export-settings") -exportSettingsElement.href = "data:application/json;base64," + btoa(resultString) -exportSettingsElement.download = "libredirect-settings.json" diff --git a/src/pages/stylesheets/styles.css b/src/pages/stylesheets/styles.css index eb599656..072b5d5b 100644 --- a/src/pages/stylesheets/styles.css +++ b/src/pages/stylesheets/styles.css @@ -477,3 +477,8 @@ input:disabled { opacity: 0.6; cursor: not-allowed; } + +div.about a { + width: 500px; + display: inline-block; +} -- cgit 1.4.1 From 6fdf65663053d2e9c951f6153f108be8d3744204 Mon Sep 17 00:00:00 2001 From: Hygna Date: Sat, 8 Oct 2022 17:48:24 +0100 Subject: Added context menu to redirect Closes https://github.com/libredirect/libredirect/issues/414 --- src/_locales/en/messages.json | 4 +++ src/assets/javascripts/services.js | 1 - src/config/config.json | 2 +- src/pages/background/background.js | 62 +++++++++++++++++++++----------------- 4 files changed, 39 insertions(+), 30 deletions(-) (limited to 'src/_locales/en') diff --git a/src/_locales/en/messages.json b/src/_locales/en/messages.json index b8dccda3..3887856c 100644 --- a/src/_locales/en/messages.json +++ b/src/_locales/en/messages.json @@ -214,5 +214,9 @@ "toggleTab": { "message": "Toggle redirects in this tab", "description": "Used in context menus when right clicking on a page/tab" + }, + "redirectLink": { + "message": "Attempt to redirect this hyperlink", + "description": "Used in context menus when right clicking on a hyperlink" } } diff --git a/src/assets/javascripts/services.js b/src/assets/javascripts/services.js index 6614bf92..80a1ac45 100644 --- a/src/assets/javascripts/services.js +++ b/src/assets/javascripts/services.js @@ -407,7 +407,6 @@ function redirect(url, type, initiator, forceRedirection) { } function computeService(url, returnFrontend) { - console.log(url) return new Promise(resolve => { fetch("/config/config.json") .then(response => response.text()) diff --git a/src/config/config.json b/src/config/config.json index 642d90ee..ff4a869f 100644 --- a/src/config/config.json +++ b/src/config/config.json @@ -414,7 +414,7 @@ }, "imageType": "svg", "embeddable": false, - "url": "https://search.joinpeertube.org" + "url": "https://joinpeertube.org" }, "lbry": { "frontends": { diff --git a/src/pages/background/background.js b/src/pages/background/background.js index 54a80011..d252e580 100644 --- a/src/pages/background/background.js +++ b/src/pages/background/background.js @@ -21,28 +21,28 @@ function initDefaults() { browser.runtime.onInstalled.addListener(details => { if (details.previousVersion != browser.runtime.getManifest().version) { - switch (details.reason) { - case "install": - initDefaults() - break - case "update": - fetch("/instances/blacklist.json") - .then(response => response.text()) - .then(async data => { - browser.storage.local.set({ blacklists: JSON.parse(data) }, async () => { - switch (details.previousVersion) { - case "2.2.0": - case "2.2.1": - await generalHelper.initDefaults() - await servicesHelper.initDefaults() - await servicesHelper.upgradeOptions() - break - default: - await servicesHelper.processUpdate() - } + switch (details.reason) { + case "install": + initDefaults() + break + case "update": + fetch("/instances/blacklist.json") + .then(response => response.text()) + .then(async data => { + browser.storage.local.set({ blacklists: JSON.parse(data) }, async () => { + switch (details.previousVersion) { + case "2.2.0": + case "2.2.1": + await generalHelper.initDefaults() + await servicesHelper.initDefaults() + await servicesHelper.upgradeOptions() + break + default: + await servicesHelper.processUpdate() + } + }) }) - }) - } + } } }) @@ -166,18 +166,21 @@ browser.contextMenus.create({ contexts: ["page", "tab"], }) +browser.contextMenus.create({ + id: "redirectLink", + title: browser.i18n.getMessage("redirectLink"), + contexts: ["link"], +}) + function handleToggleTab(tab) { return new Promise(async resolve => { - console.log(tabIdRedirects[tab.id]) switch (tabIdRedirects[tab.id]) { case false: - console.log("kj") const newUrl = await servicesHelper.reverse(tab.url, true) if (newUrl) browser.tabs.update(tab.id, { url: newUrl }) resolve() return case true: - console.log("lsad") browser.tabs.reload(tab.id) resolve() return @@ -211,14 +214,10 @@ browser.contextMenus.onClicked.addListener((info, tab) => { resolve() return } else { - console.log("n") const url = new URL(tab.url) const service = await servicesHelper.computeService(url) - console.log(service) if (service) { - console.log("h") browser.storage.local.get("options", async r => { - console.log(r.options[service]) if (r.options[service].enabled) tabIdRedirects[tab.id] = false else tabIdRedirects[tab.id] = true await handleToggleTab(tab) @@ -232,6 +231,13 @@ browser.contextMenus.onClicked.addListener((info, tab) => { return } } + 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 }) + resolve() + return } }) }) -- cgit 1.4.1