blob: 266a28b82ced720c55897f447d8aed7f6208af16 [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,
8 "fixedtoolbar": false,
9 "redirect": false,
10 "history": false
11};
12
13function cleanUpOptions(options) {
14 var ok = true;
15 for (const [opt, value] of Object.entries(defaultOptions)) {
16 if (!opt in options) {
17 ok = false;
18 options[opt] = value;
19 }
20 }
21
22 if (!ok) {
23 chrome.storage.sync.set(options);
24 }
avm99963001c07c2019-03-30 18:47:02 +010025
26 return options;
avm99963122dc9b2019-03-30 18:44:18 +010027}
28
avm99963cbea3142019-03-28 00:48:15 +010029function save() {
avm99963122dc9b2019-03-30 18:44:18 +010030 var options = defaultOptions;
31
32 Object.keys(options).forEach(function (opt) {
33 options[opt] = document.querySelector("#"+opt).checked;
34 });
35
36 chrome.storage.sync.set(options, function() {
avm99963cbea3142019-03-28 00:48:15 +010037 window.close();
38 });
39}
40
avm99963a3d1ef32019-03-30 23:33:29 +010041function i18n() {
42 var messages = ["list", "thread", "enhancements", "fixedtoolbar", "redirect", "experimental_label", "history", "save"];
43
44 messages.forEach(function(msg) {
45 console.log(msg);
46 document.querySelector("[data-i18n=\""+msg+"\"]").innerHTML = chrome.i18n.getMessage("options_"+msg);
47 });
48}
49
avm99963cbea3142019-03-28 00:48:15 +010050window.addEventListener("load", function() {
avm99963a3d1ef32019-03-30 23:33:29 +010051 i18n();
52
avm99963cbea3142019-03-28 00:48:15 +010053 chrome.storage.sync.get(null, function(items) {
avm99963001c07c2019-03-30 18:47:02 +010054 items = cleanUpOptions(items);
avm99963cbea3142019-03-28 00:48:15 +010055
avm99963122dc9b2019-03-30 18:44:18 +010056 Object.keys(defaultOptions).forEach(function(opt) {
57 if (items[opt] === true) {
58 document.querySelector("#"+opt).checked = true;
59 }
60 });
avm99963cbea3142019-03-28 00:48:15 +010061
62 document.querySelector("#save").addEventListener("click", save);
63 });
64});