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

View File

@ -85,11 +85,14 @@ 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", () => {
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 if (typeof config.services[service].options[option] == "boolean") options[service][option] = divs[service][option].checked
else options[service][option] = divs[service][option].value else options[service][option] = divs[service][option].value
browser.storage.local.set({ options }) browser.storage.local.set({ options })
changeFrontendsSettings(service) changeFrontendsSettings(service)
}) })
})
} }
if (Object.keys(config.services[service].frontends).length > 1) { if (Object.keys(config.services[service].frontends).length > 1) {