blob: 53c4e3b702becff32fe0769d9c67cb4817fc014a [file] [log] [blame]
avm99963cbea3142019-03-28 00:48:15 +01001function isEmpty(obj) {
2 return Object.keys(obj).length === 0;
3}
4
avm99963122dc9b2019-03-30 18:44:18 +01005var defaultOptions = {
6 "list": true,
7 "thread": true,
avm999636d9c5fe2019-06-04 00:35:53 +02008 "threadall": false,
avm99963122dc9b2019-03-30 18:44:18 +01009 "fixedtoolbar": false,
10 "redirect": false,
avm999636d9c5fe2019-06-04 00:35:53 +020011 "history": false,
avm99963af7860e2019-06-04 03:33:26 +020012 "loaddrafts": false,
avm99963c19497f2019-08-23 00:15:11 +020013 "batchduplicate": false,
avm99963eb2d0b82019-10-07 22:58:55 +020014 "escalatethreads": false,
15 "movethreads": false
avm99963122dc9b2019-03-30 18:44:18 +010016};
17
18function cleanUpOptions(options) {
19 var ok = true;
20 for (const [opt, value] of Object.entries(defaultOptions)) {
21 if (!opt in options) {
22 ok = false;
23 options[opt] = value;
24 }
25 }
26
27 if (!ok) {
28 chrome.storage.sync.set(options);
29 }
avm99963001c07c2019-03-30 18:47:02 +010030
31 return options;
avm99963122dc9b2019-03-30 18:44:18 +010032}
33
avm99963cbea3142019-03-28 00:48:15 +010034function save() {
avm99963122dc9b2019-03-30 18:44:18 +010035 var options = defaultOptions;
36
37 Object.keys(options).forEach(function (opt) {
38 options[opt] = document.querySelector("#"+opt).checked;
39 });
40
41 chrome.storage.sync.set(options, function() {
avm99963cbea3142019-03-28 00:48:15 +010042 window.close();
43 });
44}
45
avm99963a3d1ef32019-03-30 23:33:29 +010046function i18n() {
avm99963c19497f2019-08-23 00:15:11 +020047 document.querySelectorAll("[data-i18n]").forEach(el => el.innerHTML = chrome.i18n.getMessage("options_"+el.getAttribute("data-i18n")));
avm99963a3d1ef32019-03-30 23:33:29 +010048}
49
avm999636d9c5fe2019-06-04 00:35:53 +020050function thread() {
51 if (document.querySelector("#thread").checked && document.querySelector("#threadall").checked) {
52 document.querySelector("#"+(this.id == "thread" ? "threadall" : "thread")).checked = false;
53 }
54}
55
avm99963cbea3142019-03-28 00:48:15 +010056window.addEventListener("load", function() {
avm99963a3d1ef32019-03-30 23:33:29 +010057 i18n();
58
avm99963cbea3142019-03-28 00:48:15 +010059 chrome.storage.sync.get(null, function(items) {
avm99963001c07c2019-03-30 18:47:02 +010060 items = cleanUpOptions(items);
avm99963cbea3142019-03-28 00:48:15 +010061
avm99963122dc9b2019-03-30 18:44:18 +010062 Object.keys(defaultOptions).forEach(function(opt) {
63 if (items[opt] === true) {
64 document.querySelector("#"+opt).checked = true;
65 }
66 });
avm99963cbea3142019-03-28 00:48:15 +010067
avm999636d9c5fe2019-06-04 00:35:53 +020068 ["thread", "threadall"].forEach(el => document.querySelector("#"+el).addEventListener("change", thread));
avm99963cbea3142019-03-28 00:48:15 +010069 document.querySelector("#save").addEventListener("click", save);
70 });
71});