#32 Probably working script for a settings page?

This commit is contained in:
Serraniel 2020-11-07 16:47:31 +01:00
parent af5656f1ff
commit 88a97af8f4
Signed by: Serraniel
GPG key ID: 3690B4E7364525D3

View file

@ -1,11 +1,28 @@
import { getGlobalStorageProvider } from "./settings/storageProvider";
import { onReady } from "./utils/helpers";
onReady(() => {
});
function saveOptions() {
const OPTION_SELECTOR = '.extension-option'
function storeOptions() {
document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
getGlobalStorageProvider().setData(optionElement.id, optionElement.check);
});
}
document.getElementById('save').addEventListener('click', saveOptions)
function restoreOptions() {
document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
let defaultValue = optionElement.dataset.defaultValue === 'true' ? true : false;
getGlobalStorageProvider().getData(optionElement.id, defaultValue, value => {
optionElement.checked = value;
});
});
}
onReady(() => {
// register Store Button
document.getElementById('saveBtn').addEventListener('click', storeOptions);
// try restore options
restoreOptions();
});