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