HistoryCleaner/extension/options.js

40 lines
908 B
JavaScript
Raw Normal View History

/* global generateElementsVariable */
2018-09-09 23:02:04 +00:00
const DOM = generateElementsVariable([
"days",
"visitCount",
"mode",
"settings"
]);
function disable(mode) {
if (mode === "days") {
DOM.visitCount.disabled = true;
} else {
DOM.visitCount.disabled = false;
}
}
function updateDays(e) {
disable(DOM.mode.value);
2018-09-09 23:02:04 +00:00
browser.storage.local.set({
days: parseInt(DOM.days.value),
visitCount: parseInt(DOM.visitCount.value),
deleteMode: DOM.mode.value
2018-09-09 23:02:04 +00:00
});
2017-02-07 23:38:33 +00:00
e.preventDefault();
2017-02-07 23:31:13 +00:00
}
2018-09-09 23:02:04 +00:00
async function restoreOptions() {
const res = await browser.storage.local.get();
DOM.days.value = res.days || 0;
DOM.visitCount.value = res.visitCount || 0;
DOM.mode.value = res.deleteMode || "days";
disable(res.deleteMode);
2017-02-07 23:31:13 +00:00
}
2018-09-09 23:02:04 +00:00
DOM.settings.addEventListener("input", updateDays);
document.addEventListener("DOMContentLoaded", restoreOptions);