blob: d51843123174a296e2e81425be8c5ca7984a3055 [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,
12 "loaddrafts": false
avm99963122dc9b2019-03-30 18:44:18 +010013};
14
15function cleanUpOptions() {
16 chrome.storage.sync.get(null, function(options) {
avm999630a2840d2019-03-30 22:00:24 +010017 console.log("[cleanUpOptions] Previous options", options);
avm99963122dc9b2019-03-30 18:44:18 +010018 var ok = true;
19 for (const [opt, value] of Object.entries(defaultOptions)) {
avm999630a2840d2019-03-30 22:00:24 +010020 if (!(opt in options)) {
avm99963122dc9b2019-03-30 18:44:18 +010021 ok = false;
22 options[opt] = value;
23 }
24 }
25
avm999630a2840d2019-03-30 22:00:24 +010026 console.log("[cleanUpOptions] New options", options);
27
avm99963122dc9b2019-03-30 18:44:18 +010028 if (!ok) {
29 chrome.storage.sync.set(options);
avm99963cbea3142019-03-28 00:48:15 +010030 }
31 });
avm99963122dc9b2019-03-30 18:44:18 +010032}
33
34chrome.runtime.onInstalled.addListener(function(details) {
avm999630a2840d2019-03-30 22:00:24 +010035 if (details.reason == "install" || details.reason == "update") {
avm99963122dc9b2019-03-30 18:44:18 +010036 cleanUpOptions();
37 }
avm99963cbea3142019-03-28 00:48:15 +010038});