avm99963 | 4c1a679 | 2020-08-31 21:30:42 +0200 | [diff] [blame] | 1 | const defaultOptions = { |
| 2 | 'list': true, |
| 3 | 'thread': true, |
| 4 | 'threadall': false, |
| 5 | 'fixedtoolbar': false, |
| 6 | 'redirect': false, |
| 7 | 'history': false, |
| 8 | 'loaddrafts': false, |
| 9 | 'batchduplicate': false, |
| 10 | 'escalatethreads': false, |
| 11 | 'movethreads': false, |
| 12 | 'increasecontrast': false, |
| 13 | 'stickysidebarheaders': false, |
| 14 | 'profileindicator': false, |
avm99963 | ad65e75 | 2020-09-01 00:13:59 +0200 | [diff] [blame] | 15 | 'profileindicatoralt': false, |
| 16 | 'profileindicatoralt_months': 12, |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 17 | 'ccdarktheme': false, |
| 18 | 'ccdarktheme_mode': 'switch', |
| 19 | 'ccdarktheme_switch_enabled': true, |
avm99963 | 4c1a679 | 2020-08-31 21:30:42 +0200 | [diff] [blame] | 20 | }; |
| 21 | |
avm99963 | ad65e75 | 2020-09-01 00:13:59 +0200 | [diff] [blame] | 22 | const specialOptions = [ |
| 23 | 'profileindicatoralt_months', |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 24 | 'ccdarktheme_mode', |
| 25 | 'ccdarktheme_switch_enabled', |
avm99963 | ad65e75 | 2020-09-01 00:13:59 +0200 | [diff] [blame] | 26 | ]; |
| 27 | |
avm99963 | 4c1a679 | 2020-08-31 21:30:42 +0200 | [diff] [blame] | 28 | const deprecatedOptions = [ |
| 29 | 'escalatethreads', |
| 30 | 'movethreads', |
| 31 | 'batchduplicate', |
| 32 | ]; |
| 33 | |
| 34 | function isEmpty(obj) { |
| 35 | return Object.keys(obj).length === 0; |
| 36 | } |
| 37 | |
| 38 | function cleanUpOptions(options) { |
| 39 | console.log('[cleanUpOptions] Previous options', options); |
avm99963 | ad65e75 | 2020-09-01 00:13:59 +0200 | [diff] [blame] | 40 | |
| 41 | if (typeof options !== 'object' || options === null) { |
| 42 | options = defaultOptions; |
| 43 | } else { |
| 44 | var ok = true; |
| 45 | for (const [opt, value] of Object.entries(defaultOptions)) { |
| 46 | if (!(opt in options)) { |
| 47 | ok = false; |
| 48 | options[opt] = value; |
| 49 | } |
avm99963 | 4c1a679 | 2020-08-31 21:30:42 +0200 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| 53 | console.log('[cleanUpOptions] New options', options); |
| 54 | |
| 55 | if (!ok) { |
| 56 | chrome.storage.sync.set(options); |
| 57 | } |
| 58 | |
| 59 | return options; |
| 60 | } |