blob: 53c4e3b702becff32fe0769d9c67cb4817fc014a [file] [log] [blame]
function isEmpty(obj) {
return Object.keys(obj).length === 0;
}
var defaultOptions = {
"list": true,
"thread": true,
"threadall": false,
"fixedtoolbar": false,
"redirect": false,
"history": false,
"loaddrafts": false,
"batchduplicate": false,
"escalatethreads": false,
"movethreads": false
};
function cleanUpOptions(options) {
var ok = true;
for (const [opt, value] of Object.entries(defaultOptions)) {
if (!opt in options) {
ok = false;
options[opt] = value;
}
}
if (!ok) {
chrome.storage.sync.set(options);
}
return options;
}
function save() {
var options = defaultOptions;
Object.keys(options).forEach(function (opt) {
options[opt] = document.querySelector("#"+opt).checked;
});
chrome.storage.sync.set(options, function() {
window.close();
});
}
function i18n() {
document.querySelectorAll("[data-i18n]").forEach(el => el.innerHTML = chrome.i18n.getMessage("options_"+el.getAttribute("data-i18n")));
}
function thread() {
if (document.querySelector("#thread").checked && document.querySelector("#threadall").checked) {
document.querySelector("#"+(this.id == "thread" ? "threadall" : "thread")).checked = false;
}
}
window.addEventListener("load", function() {
i18n();
chrome.storage.sync.get(null, function(items) {
items = cleanUpOptions(items);
Object.keys(defaultOptions).forEach(function(opt) {
if (items[opt] === true) {
document.querySelector("#"+opt).checked = true;
}
});
["thread", "threadall"].forEach(el => document.querySelector("#"+el).addEventListener("change", thread));
document.querySelector("#save").addEventListener("click", save);
});
});