diff options
author | ManeraKai <manerakai@protonmail.com> | 2023-09-18 13:12:00 +0300 |
---|---|---|
committer | ManeraKai <manerakai@protonmail.com> | 2023-09-18 13:12:09 +0300 |
commit | 2e1de247ee7d1d3cb14b9e6a03b3e429a13b53ac (patch) | |
tree | 6417e4fe245d491d28ae9a4f1cbe7427b1f49a45 /src/pages/popup/popup.js | |
parent | Added cache for ping https://github.com/libredirect/browser_extension/issues/773 (diff) | |
download | libredirect-2e1de247ee7d1d3cb14b9e6a03b3e429a13b53ac.zip |
Add "Redirect (frontend) to Prefferred" https://github.com/libredirect/browser_extension/issues/767
Diffstat (limited to 'src/pages/popup/popup.js')
-rw-r--r-- | src/pages/popup/popup.js | 35 |
1 files changed, 22 insertions, 13 deletions
diff --git a/src/pages/popup/popup.js b/src/pages/popup/popup.js index f6d0a4ba..5eeb18c2 100644 --- a/src/pages/popup/popup.js +++ b/src/pages/popup/popup.js @@ -19,19 +19,37 @@ for (const service in config.services) { divs[service].all = allSites.getElementsByClassName(service)[0] divs[service].current = currSite.getElementsByClassName(service)[0] - divs[service].all_toggle = allSites.getElementsByClassName(service + "-enabled")[0] - divs[service].current_toggle = currSite.getElementsByClassName(service + "-enabled")[0] - + divs[service].all_toggle = allSites.getElementsByClassName(`${service}-enabled`)[0] divs[service].all_toggle.addEventListener("change", async () => { const options = await utils.getOptions() options[service].enabled = divs[service].all_toggle.checked browser.storage.local.set({ options }) }) + + allSites.getElementsByClassName(`${service}-change_instance`)[0].addEventListener("click", () => { + browser.tabs.query({ active: true, currentWindow: true }, async tabs => { + if (tabs[0].url) { + const url = new URL(tabs[0].url) + browser.tabs.update({ url: await servicesHelper.switchInstance(url, service) }) + } + }) + }) + + divs[service].current_toggle = currSite.getElementsByClassName(`${service}-enabled`)[0] divs[service].current_toggle.addEventListener("change", async () => { const options = await utils.getOptions() options[service].enabled = divs[service].current_toggle.checked browser.storage.local.set({ options }) }) + + currSite.getElementsByClassName(`${service}-change_instance`)[0].addEventListener("click", () => { + browser.tabs.query({ active: true, currentWindow: true }, async tabs => { + if (tabs[0].url) { + const url = new URL(tabs[0].url) + browser.tabs.update({ url: await servicesHelper.switchInstance(url, service) }) + } + }) + }) } browser.tabs.query({ active: true, currentWindow: true }, async tabs => { @@ -92,13 +110,4 @@ browser.tabs.query({ active: true, currentWindow: true }, async tabs => { currentSiteDivider.style.display = "" } } -}) - -for (const a of document.getElementsByTagName("a")) { - a.addEventListener("click", e => { - if (!a.classList.contains("prevent")) { - browser.tabs.create({ url: a.getAttribute("href") }) - e.preventDefault() - } - }) -} +}) \ No newline at end of file |