2019-06-25 15:08:59 +00:00
|
|
|
/* global generateElementsVariable */
|
|
|
|
|
2018-09-09 23:02:04 +00:00
|
|
|
const DOM = generateElementsVariable([
|
|
|
|
"days",
|
|
|
|
"visitCount",
|
|
|
|
"mode",
|
|
|
|
"settings"
|
|
|
|
]);
|
|
|
|
|
2019-06-25 15:08:59 +00:00
|
|
|
function disable(mode) {
|
|
|
|
if (mode === "days") {
|
|
|
|
DOM.visitCount.disabled = true;
|
|
|
|
} else {
|
|
|
|
DOM.visitCount.disabled = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-04-09 22:31:09 +00:00
|
|
|
function updateDays(e) {
|
2019-06-25 15:08:59 +00:00
|
|
|
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),
|
2019-06-25 15:08:59 +00:00
|
|
|
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;
|
2019-06-25 15:08:59 +00:00
|
|
|
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);
|
2017-04-09 22:31:09 +00:00
|
|
|
document.addEventListener("DOMContentLoaded", restoreOptions);
|