diff options
author | Hygna <hygna@proton.me> | 2022-10-08 11:37:45 +0100 |
---|---|---|
committer | Hygna <hygna@proton.me> | 2022-10-08 11:37:45 +0100 |
commit | be78f86a67458208279b8cb51b2c6fab4491244c (patch) | |
tree | f7a7d1ec22bb69f38350007798481a2ef3833018 /src/assets/javascripts/services.js | |
parent | Added support for fetching invidious i2p instances (diff) | |
download | libredirect-be78f86a67458208279b8cb51b2c6fab4491244c.zip |
Added context menu to toggle redirects for a certain tab
Closes https://github.com/libredirect/libredirect/issues/464
Diffstat (limited to 'src/assets/javascripts/services.js')
-rw-r--r-- | src/assets/javascripts/services.js | 28 |
1 files changed, 16 insertions, 12 deletions
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() |