2022-07-26 23:28:50 +02:00
|
|
|
"use strict"
|
|
|
|
window.browser = window.browser || window.chrome
|
|
|
|
|
2023-01-21 12:29:10 +01:00
|
|
|
import servicesHelper from "../../assets/javascripts/services.js"
|
2022-07-26 23:28:50 +02:00
|
|
|
import utils from "../../assets/javascripts/utils.js"
|
2022-05-30 00:02:59 +02:00
|
|
|
|
2023-05-04 18:56:18 +02:00
|
|
|
document.getElementById("more-options").addEventListener("click", () => browser.runtime.openOptionsPage())
|
|
|
|
|
2023-05-09 07:58:34 +02:00
|
|
|
const allSites = document.getElementById("all_sites")
|
|
|
|
const currSite = document.getElementById("current_site")
|
2023-05-04 18:56:18 +02:00
|
|
|
const currentSiteDivider = document.getElementById("current_site_divider")
|
|
|
|
|
|
|
|
const config = await utils.getConfig()
|
|
|
|
const divs = {}
|
|
|
|
|
|
|
|
for (const service in config.services) {
|
|
|
|
divs[service] = {}
|
|
|
|
|
|
|
|
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.addEventListener("change", async () => {
|
|
|
|
const options = await utils.getOptions()
|
|
|
|
options[service].enabled = divs[service].all_toggle.checked
|
|
|
|
browser.storage.local.set({ options })
|
|
|
|
})
|
|
|
|
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 })
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2023-02-08 09:28:57 +01:00
|
|
|
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
|
2023-05-04 18:56:18 +02:00
|
|
|
let url;
|
|
|
|
|
|
|
|
// Set visibility of control buttons
|
2023-03-05 15:29:09 +01:00
|
|
|
if (tabs[0].url) {
|
2023-05-04 18:56:18 +02:00
|
|
|
url = new URL(tabs[0].url)
|
2023-03-05 15:29:09 +01:00
|
|
|
servicesHelper.switchInstance(url).then(r => {
|
2023-05-04 18:56:18 +02:00
|
|
|
if (r) {
|
2023-05-09 07:58:34 +02:00
|
|
|
document.getElementById("change_instance_div").style.display = ""
|
2023-05-04 18:56:18 +02:00
|
|
|
document.getElementById("change_instance").addEventListener("click", async () =>
|
|
|
|
browser.tabs.update({ url: await servicesHelper.switchInstance(url) })
|
2023-03-05 15:29:09 +01:00
|
|
|
)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
servicesHelper.copyRaw(url, true).then(r => {
|
2023-05-04 18:56:18 +02:00
|
|
|
if (r) {
|
2023-05-09 07:58:34 +02:00
|
|
|
document.getElementById("copy_original_div").style.display = ""
|
2023-05-04 18:56:18 +02:00
|
|
|
document.getElementById("copy_original").addEventListener("click", () =>
|
|
|
|
servicesHelper.copyRaw(url)
|
|
|
|
)
|
2023-03-10 11:12:17 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
servicesHelper.reverse(url).then(r => {
|
2023-05-04 18:56:18 +02:00
|
|
|
if (r) {
|
2023-05-09 07:58:34 +02:00
|
|
|
document.getElementById("redirect_to_original_div").style.display = ""
|
2023-05-04 18:56:18 +02:00
|
|
|
document.getElementById("redirect_to_original").addEventListener("click", () =>
|
|
|
|
browser.runtime.sendMessage("reverseTab")
|
|
|
|
)
|
2023-03-10 11:12:17 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
servicesHelper.redirectAsync(url, "main_frame", null, true).then(r => {
|
2023-05-04 18:56:18 +02:00
|
|
|
if (r) {
|
2023-05-09 07:58:34 +02:00
|
|
|
document.getElementById("redirect_div").style.display = ""
|
2023-05-04 18:56:18 +02:00
|
|
|
document.getElementById("redirect").addEventListener("click", () =>
|
|
|
|
browser.runtime.sendMessage("redirectTab")
|
|
|
|
)
|
2023-03-05 15:29:09 +01:00
|
|
|
}
|
|
|
|
})
|
|
|
|
}
|
2022-10-02 16:10:36 +02:00
|
|
|
|
2023-05-04 18:56:18 +02:00
|
|
|
const options = await utils.getOptions()
|
2022-07-24 17:30:41 +02:00
|
|
|
|
2023-05-04 18:56:18 +02:00
|
|
|
// Set visibility of all service buttons
|
2023-05-09 07:58:34 +02:00
|
|
|
for (const service of options.popupServices) {
|
2023-05-04 18:56:18 +02:00
|
|
|
divs[service].all.classList.remove("hide")
|
|
|
|
divs[service].all_toggle.checked = options[service].enabled
|
2023-01-23 10:54:45 +01:00
|
|
|
}
|
2022-07-26 23:28:50 +02:00
|
|
|
|
2023-05-04 18:56:18 +02:00
|
|
|
// Set visibility of current page service button
|
|
|
|
if (url) {
|
|
|
|
const service = await servicesHelper.computeService(url)
|
|
|
|
if (service) {
|
|
|
|
divs[service].all.classList.add("hide")
|
|
|
|
divs[service].current.classList.remove("hide")
|
|
|
|
divs[service].current_toggle.checked = options[service].enabled
|
2023-05-09 07:58:34 +02:00
|
|
|
currentSiteDivider.style.display = ""
|
2022-07-26 23:28:50 +02:00
|
|
|
}
|
2023-01-23 10:54:45 +01:00
|
|
|
}
|
2022-02-02 19:22:34 +01:00
|
|
|
})
|
2022-02-01 19:37:43 +01:00
|
|
|
|
2022-07-26 23:28:50 +02:00
|
|
|
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()
|
|
|
|
}
|
|
|
|
})
|
2023-05-04 18:56:18 +02:00
|
|
|
}
|