aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHygna <hygna@proton.me>2022-10-20 16:25:17 +0100
committerHygna <hygna@proton.me>2022-10-20 16:26:00 +0100
commit1ce6a16686b9dc7c0624a9f586ec77ff8267a04b (patch)
tree303291983c2bb4aa378ccd5a39d79b3310d80f4e
parentTranslated using Weblate (Croatian) (diff)
downloadlibredirect-1ce6a16686b9dc7c0624a9f586ec77ff8267a04b.zip
Fixed all settings changed except the last one set not saving (for real this time)
Closes https://github.com/libredirect/libredirect/issues/473
-rw-r--r--src/assets/javascripts/utils.js72
-rw-r--r--src/pages/options/widgets/services.js11
2 files changed, 49 insertions, 34 deletions
diff --git a/src/assets/javascripts/utils.js b/src/assets/javascripts/utils.js
index 66a439bf..9a2d4900 100644
--- a/src/assets/javascripts/utils.js
+++ b/src/assets/javascripts/utils.js
@@ -134,26 +134,32 @@ async function processDefaultCustomInstances(service, frontend, network, documen
calcFrontendCheckBoxes()
frontendNetworkElement.getElementsByClassName("toggle-all")[0].addEventListener("change", async event => {
- if (event.target.checked) frontendDefaultRedirects = [...redirects[frontend][network]]
- else frontendDefaultRedirects = []
+ browser.storage.local.get("options", r => {
+ let options = r.options
+ if (event.target.checked) frontendDefaultRedirects = [...redirects[frontend][network]]
+ else frontendDefaultRedirects = []
- options[frontend][network].enabled = frontendDefaultRedirects
- browser.storage.local.set({ options })
- calcFrontendCheckBoxes()
+ options[frontend][network].enabled = frontendDefaultRedirects
+ 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 => {
- if (event.target.checked) frontendDefaultRedirects.push(element.className)
- else {
- let index = frontendDefaultRedirects.indexOf(element.className)
- if (index > -1) frontendDefaultRedirects.splice(index, 1)
- }
+ 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)
+ if (index > -1) frontendDefaultRedirects.splice(index, 1)
+ }
- options[frontend][network].enabled = frontendDefaultRedirects
- browser.storage.local.set({ options })
- calcFrontendCheckBoxes()
+ options[frontend][network].enabled = frontendDefaultRedirects
+ browser.storage.local.set({ options })
+ calcFrontendCheckBoxes()
+ })
})
}
@@ -174,29 +180,35 @@ async function processDefaultCustomInstances(service, frontend, network, documen
for (const item of frontendCustomInstances) {
frontendNetworkElement.getElementsByClassName(`clear-${item}`)[0].addEventListener("click", async () => {
- let index = frontendCustomInstances.indexOf(item)
- if (index > -1) frontendCustomInstances.splice(index, 1)
- options[frontend][network].custom = frontendCustomInstances
- browser.storage.local.set({ options })
- calcFrontendCustomInstances()
+ 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 => {
- event.preventDefault()
- let frontendCustomInstanceInput = frontendNetworkElement.getElementsByClassName("custom-instance")[0]
- let url = new URL(frontendCustomInstanceInput.value)
- let protocolHostVar = protocolHost(url)
- if (frontendCustomInstanceInput.validity.valid && !redirects[frontend][network].includes(protocolHostVar)) {
- if (!frontendCustomInstances.includes(protocolHostVar)) {
- frontendCustomInstances.push(protocolHostVar)
- options[frontend][network].custom = frontendCustomInstances
- browser.storage.local.set({ options })
- frontendCustomInstanceInput.value = ""
+ 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)
+ let protocolHostVar = protocolHost(url)
+ if (frontendCustomInstanceInput.validity.valid && !redirects[frontend][network].includes(protocolHostVar)) {
+ if (!frontendCustomInstances.includes(protocolHostVar)) {
+ frontendCustomInstances.push(protocolHostVar)
+ options[frontend][network].custom = frontendCustomInstances
+ browser.storage.local.set({ options })
+ frontendCustomInstanceInput.value = ""
+ }
+ calcFrontendCustomInstances()
}
- calcFrontendCustomInstances()
- }
+ })
})
}
diff --git a/src/pages/options/widgets/services.js b/src/pages/options/widgets/services.js
index eb7f1ba7..37385faa 100644
--- a/src/pages/options/widgets/services.js
+++ b/src/pages/options/widgets/services.js
@@ -85,10 +85,13 @@ for (const service in config.services) {
else divs[service][option].value = options[service][option]
divs[service][option].addEventListener("change", () => {
- 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)
+ 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)
+ })
})
}