small fix

This commit is contained in:
ManeraKai 2022-10-02 18:23:17 +03:00
parent e8a67e9172
commit 84e863c477
No known key found for this signature in database
GPG Key ID: 5ABC31FFD562E337
2 changed files with 34 additions and 25 deletions

View File

@ -376,32 +376,41 @@ function redirect(url, type, initiator) {
}
}
async function computeService(url, returnFrontend) {
fetch("/config/config.json")
.then(response => response.text())
.then(configData => {
const config = JSON.parse(configData)
browser.storage.local.get(["redirects", "options"], r => {
const redirects = r.redirects
const options = r.options
for (const service in config.services) {
if (regexArray(service, url, config)) {
if (returnFrontend) return [service, null]
else return service
} else {
for (const frontend in config.services[service].frontends) {
if (all(service, frontend, options, config, redirects).includes(utils.protocolHost(url))) {
if (returnFrontend) {
return [service, frontend]
} else return service
function computeService(url, returnFrontend) {
return new Promise(resolve => {
fetch("/config/config.json")
.then(response => response.text())
.then(configData => {
const config = JSON.parse(configData)
browser.storage.local.get(["redirects", "options"], r => {
const redirects = r.redirects
const options = r.options
for (const service in config.services) {
if (regexArray(service, url, config)) {
if (returnFrontend) {
resolve([service, null])
} else {
resolve(service)
}
return
} else {
for (const frontend in config.services[service].frontends) {
if (all(service, frontend, options, config, redirects).includes(utils.protocolHost(url))) {
if (returnFrontend) {
resolve([service, frontend])
} else {
resolve(service)
}
return
}
}
}
}
}
// if (returnFrontend) return [null, null]
// else return null
// if (returnFrontend) return [null, null]
// else return null
})
})
})
})
}
async function switchInstance(url) {

View File

@ -58,7 +58,7 @@ const currentSiteIsFrontend = document.getElementById("current_site_divider")
browser.storage.local.get("options", r => {
browser.tabs.query({ active: true, currentWindow: true }, async tabs => {
for (const service in config.services) {
for (const service in config.services) {
if (!r.options.popupServices.includes(service)) allSites.getElementsByClassName(service)[0].classList.add("hide")
else allSites.getElementsByClassName(service)[0].classList.remove("hide")
currSite.getElementsByClassName(service)[0].classList.add("hide")