2020-11-07 17:23:12 +01:00
|
|
|
import { getGlobalStorageProvider } from "./browserApi/storageProvider";
|
2020-11-07 14:43:20 +01:00
|
|
|
import { onReady } from "./utils/helpers";
|
|
|
|
|
2020-11-07 17:02:24 +01:00
|
|
|
const OPTION_SELECTOR = 'input[type="checkbox"';
|
2020-11-07 14:43:20 +01:00
|
|
|
|
2020-11-07 16:47:31 +01:00
|
|
|
function storeOptions() {
|
|
|
|
document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
|
2020-12-28 23:22:47 +01:00
|
|
|
let optionInputElement = optionElement as HTMLInputElement;
|
|
|
|
getGlobalStorageProvider().setDataAsBoolean(optionInputElement.id, optionInputElement.checked);
|
2020-11-07 16:47:31 +01:00
|
|
|
});
|
|
|
|
}
|
2020-11-07 14:43:20 +01:00
|
|
|
|
2020-11-07 16:47:31 +01:00
|
|
|
function restoreOptions() {
|
2020-12-28 23:22:47 +01:00
|
|
|
document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
|
|
|
|
let optionInputElement = optionElement as HTMLInputElement;
|
|
|
|
let defaultValue = optionInputElement.dataset.defaultValue === 'true' ? true : false;
|
2020-11-07 14:43:20 +01:00
|
|
|
|
2020-12-28 23:22:47 +01:00
|
|
|
getGlobalStorageProvider().getDataAsBoolean(optionInputElement.id, defaultValue, value => {
|
|
|
|
optionInputElement.checked = value;
|
2020-11-07 16:47:31 +01:00
|
|
|
});
|
|
|
|
});
|
2020-11-07 14:43:20 +01:00
|
|
|
}
|
|
|
|
|
2020-11-07 17:02:24 +01:00
|
|
|
function resetOptions() {
|
|
|
|
document.querySelectorAll(OPTION_SELECTOR).forEach(optionElement => {
|
2020-12-28 23:22:47 +01:00
|
|
|
let optionInputElement = optionElement as HTMLInputElement;
|
|
|
|
let defaultValue = optionInputElement.dataset.defaultValue === 'true' ? true : false;
|
2020-11-07 17:02:24 +01:00
|
|
|
|
2020-12-28 23:22:47 +01:00
|
|
|
optionInputElement.checked = defaultValue;
|
2020-11-07 17:02:24 +01:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2020-11-07 16:47:31 +01:00
|
|
|
onReady(() => {
|
|
|
|
// register Store Button
|
2020-11-07 17:02:24 +01:00
|
|
|
document.getElementById('btnSave').addEventListener('click', event => {
|
|
|
|
event.preventDefault();
|
|
|
|
storeOptions();
|
|
|
|
});
|
|
|
|
|
|
|
|
document.getElementById('btnReset').addEventListener('click', event => {
|
|
|
|
event.preventDefault();
|
|
|
|
resetOptions();
|
|
|
|
storeOptions();
|
|
|
|
})
|
2020-11-07 16:47:31 +01:00
|
|
|
|
|
|
|
// try restore options
|
|
|
|
restoreOptions();
|
2020-11-08 13:11:52 +01:00
|
|
|
|
|
|
|
// update version label
|
|
|
|
document.getElementById('version').innerText = `v${chrome.runtime.getManifest().version}`
|
2020-11-07 16:47:31 +01:00
|
|
|
});
|