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,26 +134,32 @@ async function processDefaultCustomInstances(service, frontend, network, documen
calcFrontendCheckBoxes() calcFrontendCheckBoxes()
frontendNetworkElement.getElementsByClassName("toggle-all")[0].addEventListener("change", async event => { frontendNetworkElement.getElementsByClassName("toggle-all")[0].addEventListener("change", async event => {
if (event.target.checked) frontendDefaultRedirects = [...redirects[frontend][network]] browser.storage.local.get("options", r => {
else frontendDefaultRedirects = [] let options = r.options
if (event.target.checked) frontendDefaultRedirects = [...redirects[frontend][network]]
else frontendDefaultRedirects = []
options[frontend][network].enabled = frontendDefaultRedirects options[frontend][network].enabled = frontendDefaultRedirects
browser.storage.local.set({ options }) browser.storage.local.set({ options })
calcFrontendCheckBoxes() calcFrontendCheckBoxes()
})
}) })
for (let element of frontendCheckListElement.getElementsByTagName("input")) { for (let element of frontendCheckListElement.getElementsByTagName("input")) {
if (element.className != "toggle-all") if (element.className != "toggle-all")
frontendNetworkElement.getElementsByClassName(element.className)[0].addEventListener("change", async event => { frontendNetworkElement.getElementsByClassName(element.className)[0].addEventListener("change", async event => {
if (event.target.checked) frontendDefaultRedirects.push(element.className) browser.storage.local.get("options", r => {
else { let options = r.options
let index = frontendDefaultRedirects.indexOf(element.className) if (event.target.checked) frontendDefaultRedirects.push(element.className)
if (index > -1) frontendDefaultRedirects.splice(index, 1) else {
} let index = frontendDefaultRedirects.indexOf(element.className)
if (index > -1) frontendDefaultRedirects.splice(index, 1)
}
options[frontend][network].enabled = frontendDefaultRedirects options[frontend][network].enabled = frontendDefaultRedirects
browser.storage.local.set({ options }) browser.storage.local.set({ options })
calcFrontendCheckBoxes() calcFrontendCheckBoxes()
})
}) })
} }
@ -174,29 +180,35 @@ async function processDefaultCustomInstances(service, frontend, network, documen
for (const item of frontendCustomInstances) { for (const item of frontendCustomInstances) {
frontendNetworkElement.getElementsByClassName(`clear-${item}`)[0].addEventListener("click", async () => { frontendNetworkElement.getElementsByClassName(`clear-${item}`)[0].addEventListener("click", async () => {
let index = frontendCustomInstances.indexOf(item) browser.storage.local.get("options", r => {
if (index > -1) frontendCustomInstances.splice(index, 1) let options = r.options
options[frontend][network].custom = frontendCustomInstances let index = frontendCustomInstances.indexOf(item)
browser.storage.local.set({ options }) if (index > -1) frontendCustomInstances.splice(index, 1)
calcFrontendCustomInstances() options[frontend][network].custom = frontendCustomInstances
browser.storage.local.set({ options })
calcFrontendCustomInstances()
})
}) })
} }
} }
calcFrontendCustomInstances() calcFrontendCustomInstances()
frontendNetworkElement.getElementsByClassName("custom-instance-form")[0].addEventListener("submit", async event => { frontendNetworkElement.getElementsByClassName("custom-instance-form")[0].addEventListener("submit", async event => {
event.preventDefault() browser.storage.local.get("options", r => {
let frontendCustomInstanceInput = frontendNetworkElement.getElementsByClassName("custom-instance")[0] let options = r.options
let url = new URL(frontendCustomInstanceInput.value) event.preventDefault()
let protocolHostVar = protocolHost(url) let frontendCustomInstanceInput = frontendNetworkElement.getElementsByClassName("custom-instance")[0]
if (frontendCustomInstanceInput.validity.valid && !redirects[frontend][network].includes(protocolHostVar)) { let url = new URL(frontendCustomInstanceInput.value)
if (!frontendCustomInstances.includes(protocolHostVar)) { let protocolHostVar = protocolHost(url)
frontendCustomInstances.push(protocolHostVar) if (frontendCustomInstanceInput.validity.valid && !redirects[frontend][network].includes(protocolHostVar)) {
options[frontend][network].custom = frontendCustomInstances if (!frontendCustomInstances.includes(protocolHostVar)) {
browser.storage.local.set({ options }) frontendCustomInstances.push(protocolHostVar)
frontendCustomInstanceInput.value = "" options[frontend][network].custom = frontendCustomInstances
browser.storage.local.set({ options })
frontendCustomInstanceInput.value = ""
}
calcFrontendCustomInstances()
} }
calcFrontendCustomInstances() })
}
}) })
} }

View File

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