ThunderAI/options/mzta-options.js
2024-04-01 22:58:39 +02:00

31 lines
830 B
JavaScript

function saveOptions(e) {
e.preventDefault();
let options = {};
document.querySelectorAll(".option-input").forEach(element => {
options[element.id] = element.checked;
});
browser.storage.sync.set(options);
}
function restoreOptions() {
function setCurrentChoice(result) {
document.querySelectorAll(".option-input").forEach(element => {
element.checked = result[element.id] || false;
});
}
function onError(error) {
console.log(`Error: ${error}`);
}
let getting = browser.storage.sync.get(null);
getting.then(setCurrentChoice, onError);
}
document.addEventListener('DOMContentLoaded', () => {
restoreOptions();
i18n.updateDocument();
document.querySelectorAll(".option-input").forEach(element => {
element.addEventListener("change", saveOptions);
});
}, { once: true });