blob: 663ca281ba0094a22dd00dd68da32f542f5f1ecf [file] [log] [blame]
avm999634c1a6792020-08-31 21:30:42 +02001const 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,
avm99963ad65e752020-09-01 00:13:59 +020015 'profileindicatoralt': false,
16 'profileindicatoralt_months': 12,
avm999630bc113a2020-09-07 13:02:11 +020017 'ccdarktheme': false,
18 'ccdarktheme_mode': 'switch',
19 'ccdarktheme_switch_enabled': true,
avm99963129942f2020-09-08 02:07:18 +020020 'ccforcehidedrawer': false,
avm999638e0c1002020-12-03 16:54:20 +010021 'ccdragndropfix': false,
avm99963f5923962020-12-07 16:44:37 +010022 'batchlock': false,
avm99963b38b7412020-12-11 17:59:02 +010023 'smei_sortdirection': false,
avm99963698d3762021-02-16 01:19:54 +010024 'enhancedannouncementsdot': false,
avm999634c1a6792020-08-31 21:30:42 +020025};
26
avm99963ad65e752020-09-01 00:13:59 +020027const specialOptions = [
28 'profileindicatoralt_months',
avm999630bc113a2020-09-07 13:02:11 +020029 'ccdarktheme_mode',
30 'ccdarktheme_switch_enabled',
avm999638e0c1002020-12-03 16:54:20 +010031 'ccdragndropfix',
avm99963ad65e752020-09-01 00:13:59 +020032];
33
avm999634c1a6792020-08-31 21:30:42 +020034const deprecatedOptions = [
35 'escalatethreads',
36 'movethreads',
37 'batchduplicate',
38];
39
40function isEmpty(obj) {
41 return Object.keys(obj).length === 0;
42}
43
44function cleanUpOptions(options) {
45 console.log('[cleanUpOptions] Previous options', options);
avm99963ad65e752020-09-01 00:13:59 +020046
47 if (typeof options !== 'object' || options === null) {
48 options = defaultOptions;
49 } else {
50 var ok = true;
51 for (const [opt, value] of Object.entries(defaultOptions)) {
52 if (!(opt in options)) {
53 ok = false;
54 options[opt] = value;
55 }
avm999634c1a6792020-08-31 21:30:42 +020056 }
57 }
58
59 console.log('[cleanUpOptions] New options', options);
60
61 if (!ok) {
62 chrome.storage.sync.set(options);
63 }
64
65 return options;
66}
avm999638e0c1002020-12-03 16:54:20 +010067
68// This method is based on the fact that when building the extension for Firefox
69// the browser_specific_settings.gecko entry is included.
70function isFirefox() {
71 var manifest = chrome.runtime.getManifest();
72 return manifest.browser_specific_settings !== undefined &&
73 manifest.browser_specific_settings.gecko !== undefined;
74}