avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 1 | function isEmpty(obj) { |
| 2 | return Object.keys(obj).length === 0; |
| 3 | } |
| 4 | |
avm99963 | adf9086 | 2020-04-12 13:27:45 +0200 | [diff] [blame] | 5 | const defaultOptions = { |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 6 | '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, |
avm99963 | 129fb50 | 2020-08-28 05:18:53 +0200 | [diff] [blame] | 18 | 'profileindicator': false, |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 19 | }; |
| 20 | |
| 21 | function cleanUpOptions() { |
| 22 | chrome.storage.sync.get(null, function(options) { |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 23 | console.log('[cleanUpOptions] Previous options', options); |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 24 | var ok = true; |
| 25 | for (const [opt, value] of Object.entries(defaultOptions)) { |
avm99963 | 0a2840d | 2019-03-30 22:00:24 +0100 | [diff] [blame] | 26 | if (!(opt in options)) { |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 27 | ok = false; |
| 28 | options[opt] = value; |
| 29 | } |
| 30 | } |
| 31 | |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 32 | console.log('[cleanUpOptions] New options', options); |
avm99963 | 0a2840d | 2019-03-30 22:00:24 +0100 | [diff] [blame] | 33 | |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 34 | if (!ok) { |
| 35 | chrome.storage.sync.set(options); |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 36 | } |
| 37 | }); |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 38 | } |
| 39 | |
| 40 | chrome.runtime.onInstalled.addListener(function(details) { |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 41 | if (details.reason == 'install' || details.reason == 'update') { |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 42 | cleanUpOptions(); |
| 43 | } |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 44 | }); |
avm99963 | 1a1d2b7 | 2020-08-20 03:15:20 +0200 | [diff] [blame] | 45 | |
| 46 | chrome.browserAction.onClicked.addListener(function() { |
| 47 | chrome.runtime.openOptionsPage(); |
| 48 | }); |