blob: 6728e07952ebeff81344250f3ef3b3e664955499 [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,
avm99963129fb502020-08-28 05:18:53 +020018 'profileindicator': false,
avm99963122dc9b2019-03-30 18:44:18 +010019};
20
21function cleanUpOptions() {
22 chrome.storage.sync.get(null, function(options) {
avm99963b69eb3d2020-08-20 02:03:44 +020023 console.log('[cleanUpOptions] Previous options', options);
avm99963122dc9b2019-03-30 18:44:18 +010024 var ok = true;
25 for (const [opt, value] of Object.entries(defaultOptions)) {
avm999630a2840d2019-03-30 22:00:24 +010026 if (!(opt in options)) {
avm99963122dc9b2019-03-30 18:44:18 +010027 ok = false;
28 options[opt] = value;
29 }
30 }
31
avm99963b69eb3d2020-08-20 02:03:44 +020032 console.log('[cleanUpOptions] New options', options);
avm999630a2840d2019-03-30 22:00:24 +010033
avm99963122dc9b2019-03-30 18:44:18 +010034 if (!ok) {
35 chrome.storage.sync.set(options);
avm99963cbea3142019-03-28 00:48:15 +010036 }
37 });
avm99963122dc9b2019-03-30 18:44:18 +010038}
39
40chrome.runtime.onInstalled.addListener(function(details) {
avm99963b69eb3d2020-08-20 02:03:44 +020041 if (details.reason == 'install' || details.reason == 'update') {
avm99963122dc9b2019-03-30 18:44:18 +010042 cleanUpOptions();
43 }
avm99963cbea3142019-03-28 00:48:15 +010044});
avm999631a1d2b72020-08-20 03:15:20 +020045
46chrome.browserAction.onClicked.addListener(function() {
47 chrome.runtime.openOptionsPage();
48});