blob: e97a24e11dec913d7417f8b3194cfa5700212ad4 [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 = {
avm99963b69eb3d2020-08-20 02:03:44 +02006 'list': true,
7 'thread': true,
8 'threadall': false,
9 'fixedtoolbar': false,
10 'redirect': false,
11 'history': false,
12 'loaddrafts': false,
13 'batchduplicate': false,
14 'escalatethreads': false,
15 'movethreads': false,
16 'increasecontrast': false,
17 'stickysidebarheaders': false,
avm99963122dc9b2019-03-30 18:44:18 +010018};
19
20function cleanUpOptions() {
21 chrome.storage.sync.get(null, function(options) {
avm99963b69eb3d2020-08-20 02:03:44 +020022 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
avm99963b69eb3d2020-08-20 02:03:44 +020031 console.log('[cleanUpOptions] New options', options);
avm999630a2840d2019-03-30 22:00:24 +010032
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) {
avm99963b69eb3d2020-08-20 02:03:44 +020040 if (details.reason == 'install' || details.reason == 'update') {
avm99963122dc9b2019-03-30 18:44:18 +010041 cleanUpOptions();
42 }
avm99963cbea3142019-03-28 00:48:15 +010043});
avm999631a1d2b72020-08-20 03:15:20 +020044
45chrome.browserAction.onClicked.addListener(function() {
46 chrome.runtime.openOptionsPage();
47});