From 2e1de247ee7d1d3cb14b9e6a03b3e429a13b53ac Mon Sep 17 00:00:00 2001 From: ManeraKai Date: Mon, 18 Sep 2023 13:12:00 +0300 Subject: Add "Redirect (frontend) to Prefferred" https://github.com/libredirect/browser_extension/issues/767 --- src/pages/popup/popup.js | 35 ++++++++++++++++++++++------------- 1 file changed, 22 insertions(+), 13 deletions(-) (limited to 'src/pages/popup/popup.js') 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 -- cgit 1.4.1