2020-11-07 16:47:31 +01:00
|
|
|
import { getGlobalStorageProvider } from "./settings/storageProvider";
|
2020-11-07 14:43:20 +01:00
|
|
|
import { onReady } from "./utils/helpers";
|
|
|
|
|
2020-11-07 16:47:31 +01:00
|
|
|
const OPTION_SELECTOR = '.extension-option'
|
2020-11-07 14:43:20 +01:00
|
|
|
|
2020-11-07 16:47:31 +01:00
|
|
|
function storeOptions() {
|
|
|
|
document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
|
|
|
|
getGlobalStorageProvider().setData(optionElement.id, optionElement.check);
|
|
|
|
});
|
|
|
|
}
|
2020-11-07 14:43:20 +01:00
|
|
|
|
2020-11-07 16:47:31 +01:00
|
|
|
function restoreOptions() {
|
|
|
|
document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
|
|
|
|
let defaultValue = optionElement.dataset.defaultValue === 'true' ? true : false;
|
2020-11-07 14:43:20 +01:00
|
|
|
|
2020-11-07 16:47:31 +01:00
|
|
|
getGlobalStorageProvider().getData(optionElement.id, defaultValue, value => {
|
|
|
|
optionElement.checked = value;
|
|
|
|
});
|
|
|
|
});
|
2020-11-07 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
2020-11-07 16:47:31 +01:00
|
|
|
onReady(() => {
|
|
|
|
// register Store Button
|
|
|
|
document.getElementById('saveBtn').addEventListener('click', storeOptions);
|
|
|
|
|
|
|
|
// try restore options
|
|
|
|
restoreOptions();
|
|
|
|
});
|