Fixed all settings changed except the last one set not saving (for real this time)

Closes https://github.com/libredirect/libredirect/issues/473
This commit is contained in:
Hygna 2022-10-20 16:25:17 +01:00
parent fead1fef66
commit 1ce6a16686
No known key found for this signature in database
2 changed files with 49 additions and 34 deletions

View File

@ -134,6 +134,8 @@ async function processDefaultCustomInstances(service, frontend, network, documen
calcFrontendCheckBoxes()
frontendNetworkElement.getElementsByClassName("toggle-all")[0].addEventListener("change", async event => {
browser.storage.local.get("options", r => {
let options = r.options
if (event.target.checked) frontendDefaultRedirects = [...redirects[frontend][network]]
else frontendDefaultRedirects = []
@ -141,10 +143,13 @@ async function processDefaultCustomInstances(service, frontend, network, documen
browser.storage.local.set({ options })
calcFrontendCheckBoxes()
})
})
for (let element of frontendCheckListElement.getElementsByTagName("input")) {
if (element.className != "toggle-all")
frontendNetworkElement.getElementsByClassName(element.className)[0].addEventListener("change", async event => {
browser.storage.local.get("options", r => {
let options = r.options
if (event.target.checked) frontendDefaultRedirects.push(element.className)
else {
let index = frontendDefaultRedirects.indexOf(element.className)
@ -155,6 +160,7 @@ async function processDefaultCustomInstances(service, frontend, network, documen
browser.storage.local.set({ options })
calcFrontendCheckBoxes()
})
})
}
function calcFrontendCustomInstances() {
@ -174,16 +180,21 @@ async function processDefaultCustomInstances(service, frontend, network, documen
for (const item of frontendCustomInstances) {
frontendNetworkElement.getElementsByClassName(`clear-${item}`)[0].addEventListener("click", async () => {
browser.storage.local.get("options", r => {
let options = r.options
let index = frontendCustomInstances.indexOf(item)
if (index > -1) frontendCustomInstances.splice(index, 1)
options[frontend][network].custom = frontendCustomInstances
browser.storage.local.set({ options })
calcFrontendCustomInstances()
})
})
}
}
calcFrontendCustomInstances()
frontendNetworkElement.getElementsByClassName("custom-instance-form")[0].addEventListener("submit", async event => {
browser.storage.local.get("options", r => {
let options = r.options
event.preventDefault()
let frontendCustomInstanceInput = frontendNetworkElement.getElementsByClassName("custom-instance")[0]
let url = new URL(frontendCustomInstanceInput.value)
@ -198,6 +209,7 @@ async function processDefaultCustomInstances(service, frontend, network, documen
calcFrontendCustomInstances()
}
})
})
}
function ping(href) {

View File

@ -85,11 +85,14 @@ for (const service in config.services) {
else divs[service][option].value = options[service][option]
divs[service][option].addEventListener("change", () => {
browser.storage.local.get("options", r => {
let options = r.options
if (typeof config.services[service].options[option] == "boolean") options[service][option] = divs[service][option].checked
else options[service][option] = divs[service][option].value
browser.storage.local.set({ options })
changeFrontendsSettings(service)
})
})
}
if (Object.keys(config.services[service].frontends).length > 1) {