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 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 6 | "list": true, |
| 7 | "thread": true, |
avm99963 | 6d9c5fe | 2019-06-04 00:35:53 +0200 | [diff] [blame] | 8 | "threadall": false, |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 9 | "fixedtoolbar": false, |
| 10 | "redirect": false, |
avm99963 | 6d9c5fe | 2019-06-04 00:35:53 +0200 | [diff] [blame] | 11 | "history": false, |
avm99963 | af7860e | 2019-06-04 03:33:26 +0200 | [diff] [blame] | 12 | "loaddrafts": false, |
avm99963 | c19497f | 2019-08-23 00:15:11 +0200 | [diff] [blame] | 13 | "batchduplicate": false, |
avm99963 | eb2d0b8 | 2019-10-07 22:58:55 +0200 | [diff] [blame] | 14 | "escalatethreads": false, |
avm99963 | ae6a26d | 2020-04-12 14:03:51 +0200 | [diff] [blame] | 15 | "movethreads": false, |
| 16 | "increasecontrast": false |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 17 | }; |
| 18 | |
| 19 | function cleanUpOptions() { |
| 20 | chrome.storage.sync.get(null, function(options) { |
avm99963 | 0a2840d | 2019-03-30 22:00:24 +0100 | [diff] [blame] | 21 | console.log("[cleanUpOptions] Previous options", options); |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 22 | var ok = true; |
| 23 | for (const [opt, value] of Object.entries(defaultOptions)) { |
avm99963 | 0a2840d | 2019-03-30 22:00:24 +0100 | [diff] [blame] | 24 | if (!(opt in options)) { |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 25 | ok = false; |
| 26 | options[opt] = value; |
| 27 | } |
| 28 | } |
| 29 | |
avm99963 | 0a2840d | 2019-03-30 22:00:24 +0100 | [diff] [blame] | 30 | console.log("[cleanUpOptions] New options", options); |
| 31 | |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 32 | if (!ok) { |
| 33 | chrome.storage.sync.set(options); |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 34 | } |
| 35 | }); |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 36 | } |
| 37 | |
| 38 | chrome.runtime.onInstalled.addListener(function(details) { |
avm99963 | 0a2840d | 2019-03-30 22:00:24 +0100 | [diff] [blame] | 39 | if (details.reason == "install" || details.reason == "update") { |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 40 | cleanUpOptions(); |
| 41 | } |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 42 | }); |