2022-07-26 23:28:50 +02:00
|
|
|
"use strict"
|
|
|
|
window.browser = window.browser || window.chrome
|
|
|
|
|
|
|
|
import utils from "../../assets/javascripts/utils.js"
|
|
|
|
import generalHelper from "../../assets/javascripts/general.js"
|
2022-09-23 21:57:25 +02:00
|
|
|
import serviceHelper from "../../assets/javascripts/services.js"
|
2022-05-30 00:02:59 +02:00
|
|
|
|
|
|
|
utils.switchInstance(true).then(r => {
|
2022-07-26 23:28:50 +02:00
|
|
|
if (!r) document.getElementById("change_instance_div").style.display = "none"
|
|
|
|
else document.getElementById("change_instance").addEventListener("click", () => utils.switchInstance(false))
|
|
|
|
})
|
2022-05-30 00:02:59 +02:00
|
|
|
|
|
|
|
utils.copyRaw(true).then(r => {
|
2022-07-26 23:28:50 +02:00
|
|
|
if (!r) document.getElementById("copy_raw_div").style.display = "none"
|
|
|
|
else {
|
|
|
|
const copy_raw = document.getElementById("copy_raw")
|
|
|
|
copy_raw.addEventListener("click", () => utils.copyRaw(false, copy_raw))
|
|
|
|
}
|
2022-05-30 00:02:59 +02:00
|
|
|
})
|
2022-07-26 23:28:50 +02:00
|
|
|
document.getElementById("more-options").addEventListener("click", () => browser.runtime.openOptionsPage())
|
2022-05-30 00:02:59 +02:00
|
|
|
|
2022-09-23 21:57:25 +02:00
|
|
|
let config
|
|
|
|
let divs = {}
|
|
|
|
|
|
|
|
async function getConfig() {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
fetch("/config/config.json")
|
|
|
|
.then(response => response.text())
|
|
|
|
.then(data => {
|
|
|
|
const tmp = JSON.parse(data)
|
|
|
|
config = tmp.config
|
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2022-06-23 07:34:57 +02:00
|
|
|
|
2022-09-23 21:57:25 +02:00
|
|
|
await getConfig()
|
2022-06-23 07:34:57 +02:00
|
|
|
|
2022-09-23 21:57:25 +02:00
|
|
|
const allSites = document.getElementsByClassName("all_sites")[0]
|
|
|
|
const currSite = document.getElementsByClassName("current_site")[0]
|
2022-06-23 07:34:57 +02:00
|
|
|
|
2022-09-23 21:57:25 +02:00
|
|
|
function setDivs() {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
for (const service in config.services) {
|
|
|
|
divs[service] = {}
|
|
|
|
divs[service].toggle = {}
|
|
|
|
divs[service].current = currSite.getElementsByClassName(service)[0]
|
|
|
|
divs[service].all = allSites.getElementsByClassName(service)[0]
|
|
|
|
divs[service].toggle.current = currSite.getElementsByClassName(service + "-enabled")[0]
|
|
|
|
divs[service].toggle.all = allSites.getElementsByClassName(service + "-enabled")[0]
|
|
|
|
}
|
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
}
|
2022-06-23 07:34:57 +02:00
|
|
|
|
2022-09-23 21:57:25 +02:00
|
|
|
await setDivs()
|
2019-10-07 13:59:31 +02:00
|
|
|
|
2022-07-26 23:28:50 +02:00
|
|
|
const currentSiteIsFrontend = document.getElementById("current_site_divider")
|
2022-07-24 17:30:41 +02:00
|
|
|
|
2022-09-23 21:57:25 +02:00
|
|
|
function getEnabled() {
|
|
|
|
return new Promise(async resolve => {
|
|
|
|
for (const service in config.services) {
|
|
|
|
browser.storage.local.get(`${service}Enabled`, r => {
|
|
|
|
divs[service].toggle.all.checked = r[service + "Enabled"]
|
|
|
|
divs[service].toggle.current.checked = r[service + "Enabled"]
|
|
|
|
})
|
|
|
|
}
|
|
|
|
resolve()
|
|
|
|
})
|
|
|
|
}
|
2022-07-26 23:28:50 +02:00
|
|
|
|
2022-09-23 21:57:25 +02:00
|
|
|
browser.storage.local.get("popupFrontends", r => {
|
|
|
|
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
|
|
|
|
for (const frontend of generalHelper.allPopupFrontends) {
|
|
|
|
if (!r.popupFrontends.includes(frontend)) allSites.getElementsByClassName(frontend)[0].classList.add("hide")
|
|
|
|
else allSites.getElementsByClassName(frontend)[0].classList.remove("hide")
|
|
|
|
currSite.getElementsByClassName(frontend)[0].classList.add("hide")
|
|
|
|
}
|
2022-07-26 23:28:50 +02:00
|
|
|
|
2022-09-23 21:57:25 +02:00
|
|
|
let url
|
|
|
|
try {
|
|
|
|
url = new URL(tabs[0].url)
|
|
|
|
console.log(url.href)
|
|
|
|
} catch {
|
|
|
|
currentSiteIsFrontend.classList.add("hide")
|
|
|
|
return
|
|
|
|
}
|
2022-07-26 23:28:50 +02:00
|
|
|
|
2022-09-23 21:57:25 +02:00
|
|
|
await getEnabled()
|
|
|
|
|
|
|
|
const currentService = serviceHelper.computeService(url)
|
|
|
|
if (currentService != null) {
|
|
|
|
divs[currentService].current.classList.remove("hide")
|
|
|
|
divs[currentService].all.classList.add("hide")
|
|
|
|
if (config.services[currentService].preferences != {}) {
|
|
|
|
const unify = document.getElementById("unify")
|
|
|
|
const textElement = document.getElementById("unify").getElementsByTagName("h4")[0]
|
|
|
|
unify.addEventListener("click", () => {
|
|
|
|
const oldHtml = textElement.innerHTML
|
|
|
|
textElement.innerHTML = "..."
|
|
|
|
browser.runtime.sendMessage({ function: "unify" }, response => {
|
|
|
|
if (response && response.response) textElement.innerHTML = oldHtml
|
|
|
|
})
|
|
|
|
})
|
2022-07-26 23:28:50 +02:00
|
|
|
} else {
|
2022-09-23 21:57:25 +02:00
|
|
|
document.getElementById("unify_div").style.display = "none"
|
2022-07-26 23:28:50 +02:00
|
|
|
}
|
2022-09-23 21:57:25 +02:00
|
|
|
} else {
|
|
|
|
currentSiteIsFrontend.classList.add("hide")
|
|
|
|
document.getElementById("unify_div").style.display = "none"
|
2022-07-26 23:28:50 +02:00
|
|
|
}
|
2022-09-23 21:57:25 +02:00
|
|
|
})
|
2022-02-02 19:22:34 +01:00
|
|
|
})
|
2022-02-01 19:37:43 +01:00
|
|
|
|
2022-09-23 21:57:25 +02:00
|
|
|
for (const service in config.services) {
|
|
|
|
divs[service].toggle.all.addEventListener("change", () => {
|
|
|
|
browser.storage.local.set({
|
|
|
|
[service + "Enabled"]: divs[service].toggle.all.checked,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
divs[service].toggle.current.addEventListener("change", () => {
|
|
|
|
browser.storage.local.set({
|
|
|
|
[service + "Enabled"]: divs[service].toggle.current.checked,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
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()
|
|
|
|
}
|
|
|
|
})
|
2022-07-21 22:30:46 +02:00
|
|
|
}
|