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 | 129942f | 2020-09-08 02:07:18 +0200 | [diff] [blame] | 20 | 'ccforcehidedrawer': false, |
avm99963 | 8e0c100 | 2020-12-03 16:54:20 +0100 | [diff] [blame] | 21 | 'ccdragndropfix': false, |
avm99963 | f592396 | 2020-12-07 16:44:37 +0100 | [diff] [blame] | 22 | 'batchlock': false, |
avm99963 | b38b741 | 2020-12-11 17:59:02 +0100 | [diff] [blame] | 23 | 'smei_sortdirection': false, |
avm99963 | 698d376 | 2021-02-16 01:19:54 +0100 | [diff] [blame] | 24 | 'enhancedannouncementsdot': false, |
avm99963 | d98126f | 2021-02-17 10:44:36 +0100 | [diff] [blame] | 25 | 'repositionexpandthread': false, |
avm99963 | 4c1a679 | 2020-08-31 21:30:42 +0200 | [diff] [blame] | 26 | }; |
| 27 | |
avm99963 | ad65e75 | 2020-09-01 00:13:59 +0200 | [diff] [blame] | 28 | const specialOptions = [ |
| 29 | 'profileindicatoralt_months', |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 30 | 'ccdarktheme_mode', |
| 31 | 'ccdarktheme_switch_enabled', |
avm99963 | 8e0c100 | 2020-12-03 16:54:20 +0100 | [diff] [blame] | 32 | 'ccdragndropfix', |
avm99963 | ad65e75 | 2020-09-01 00:13:59 +0200 | [diff] [blame] | 33 | ]; |
| 34 | |
avm99963 | 4c1a679 | 2020-08-31 21:30:42 +0200 | [diff] [blame] | 35 | const deprecatedOptions = [ |
| 36 | 'escalatethreads', |
| 37 | 'movethreads', |
| 38 | 'batchduplicate', |
| 39 | ]; |
| 40 | |
| 41 | function isEmpty(obj) { |
| 42 | return Object.keys(obj).length === 0; |
| 43 | } |
| 44 | |
| 45 | function cleanUpOptions(options) { |
| 46 | console.log('[cleanUpOptions] Previous options', options); |
avm99963 | ad65e75 | 2020-09-01 00:13:59 +0200 | [diff] [blame] | 47 | |
| 48 | if (typeof options !== 'object' || options === null) { |
| 49 | options = defaultOptions; |
| 50 | } else { |
| 51 | var ok = true; |
| 52 | for (const [opt, value] of Object.entries(defaultOptions)) { |
| 53 | if (!(opt in options)) { |
| 54 | ok = false; |
| 55 | options[opt] = value; |
| 56 | } |
avm99963 | 4c1a679 | 2020-08-31 21:30:42 +0200 | [diff] [blame] | 57 | } |
| 58 | } |
| 59 | |
| 60 | console.log('[cleanUpOptions] New options', options); |
| 61 | |
| 62 | if (!ok) { |
| 63 | chrome.storage.sync.set(options); |
| 64 | } |
| 65 | |
| 66 | return options; |
| 67 | } |
avm99963 | 8e0c100 | 2020-12-03 16:54:20 +0100 | [diff] [blame] | 68 | |
| 69 | // This method is based on the fact that when building the extension for Firefox |
| 70 | // the browser_specific_settings.gecko entry is included. |
| 71 | function isFirefox() { |
| 72 | var manifest = chrome.runtime.getManifest(); |
| 73 | return manifest.browser_specific_settings !== undefined && |
| 74 | manifest.browser_specific_settings.gecko !== undefined; |
| 75 | } |