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 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 5 | var defaultOptions = { |
| 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, |
| 15 | "movethreads": false |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 16 | }; |
| 17 | |
| 18 | function cleanUpOptions() { |
| 19 | chrome.storage.sync.get(null, function(options) { |
avm99963 | 0a2840d | 2019-03-30 22:00:24 +0100 | [diff] [blame] | 20 | console.log("[cleanUpOptions] Previous options", options); |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 21 | var ok = true; |
| 22 | for (const [opt, value] of Object.entries(defaultOptions)) { |
avm99963 | 0a2840d | 2019-03-30 22:00:24 +0100 | [diff] [blame] | 23 | if (!(opt in options)) { |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 24 | ok = false; |
| 25 | options[opt] = value; |
| 26 | } |
| 27 | } |
| 28 | |
avm99963 | 0a2840d | 2019-03-30 22:00:24 +0100 | [diff] [blame] | 29 | console.log("[cleanUpOptions] New options", options); |
| 30 | |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 31 | if (!ok) { |
| 32 | chrome.storage.sync.set(options); |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 33 | } |
| 34 | }); |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 35 | } |
| 36 | |
| 37 | chrome.runtime.onInstalled.addListener(function(details) { |
avm99963 | 0a2840d | 2019-03-30 22:00:24 +0100 | [diff] [blame] | 38 | if (details.reason == "install" || details.reason == "update") { |
avm99963 | 122dc9b | 2019-03-30 18:44:18 +0100 | [diff] [blame] | 39 | cleanUpOptions(); |
| 40 | } |
avm99963 | cbea314 | 2019-03-28 00:48:15 +0100 | [diff] [blame] | 41 | }); |