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