blob: 315d6d8652bdd5ba8b2db55ed14126a9ab114c07 [file] [log] [blame]
avm99963cbea3142019-03-28 00:48:15 +01001function isEmpty(obj) {
2 return Object.keys(obj).length === 0;
3}
4
avm99963adf90862020-04-12 13:27:45 +02005const defaultOptions = {
avm99963122dc9b2019-03-30 18:44:18 +01006 "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,
avm99963ae6a26d2020-04-12 14:03:51 +020015 "movethreads": false,
avm999630f9503f2020-07-27 13:56:52 +020016 "increasecontrast": false,
17 "stickysidebarheaders": false
avm99963122dc9b2019-03-30 18:44:18 +010018};
19
20function cleanUpOptions() {
21 chrome.storage.sync.get(null, function(options) {
avm999630a2840d2019-03-30 22:00:24 +010022 console.log("[cleanUpOptions] Previous options", options);
avm99963122dc9b2019-03-30 18:44:18 +010023 var ok = true;
24 for (const [opt, value] of Object.entries(defaultOptions)) {
avm999630a2840d2019-03-30 22:00:24 +010025 if (!(opt in options)) {
avm99963122dc9b2019-03-30 18:44:18 +010026 ok = false;
27 options[opt] = value;
28 }
29 }
30
avm999630a2840d2019-03-30 22:00:24 +010031 console.log("[cleanUpOptions] New options", options);
32
avm99963122dc9b2019-03-30 18:44:18 +010033 if (!ok) {
34 chrome.storage.sync.set(options);
avm99963cbea3142019-03-28 00:48:15 +010035 }
36 });
avm99963122dc9b2019-03-30 18:44:18 +010037}
38
39chrome.runtime.onInstalled.addListener(function(details) {
avm999630a2840d2019-03-30 22:00:24 +010040 if (details.reason == "install" || details.reason == "update") {
avm99963122dc9b2019-03-30 18:44:18 +010041 cleanUpOptions();
42 }
avm99963cbea3142019-03-28 00:48:15 +010043});