blob: de7c93e28c520ec8df1782bc4274c4605a6d3845 [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() {
14 chrome.storage.sync.get(null, function(options) {
avm999630a2840d2019-03-30 22:00:24 +010015 console.log("[cleanUpOptions] Previous options", options);
avm99963122dc9b2019-03-30 18:44:18 +010016 var ok = true;
17 for (const [opt, value] of Object.entries(defaultOptions)) {
avm999630a2840d2019-03-30 22:00:24 +010018 if (!(opt in options)) {
avm99963122dc9b2019-03-30 18:44:18 +010019 ok = false;
20 options[opt] = value;
21 }
22 }
23
avm999630a2840d2019-03-30 22:00:24 +010024 console.log("[cleanUpOptions] New options", options);
25
avm99963122dc9b2019-03-30 18:44:18 +010026 if (!ok) {
27 chrome.storage.sync.set(options);
avm99963cbea3142019-03-28 00:48:15 +010028 }
29 });
avm99963122dc9b2019-03-30 18:44:18 +010030}
31
32chrome.runtime.onInstalled.addListener(function(details) {
avm999630a2840d2019-03-30 22:00:24 +010033 if (details.reason == "install" || details.reason == "update") {
avm99963122dc9b2019-03-30 18:44:18 +010034 cleanUpOptions();
35 }
avm99963cbea3142019-03-28 00:48:15 +010036});