diff options
Diffstat (limited to '')
| -rw-r--r-- | src/_locales/en/messages.json | 4 | ||||
| -rw-r--r-- | src/assets/javascripts/services.js | 28 | ||||
| -rw-r--r-- | src/pages/background/background.js | 67 |
3 files changed, 65 insertions, 34 deletions
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: ["<all_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) => { |
