blob: 6bfdf02dfe3e4016b9275c5546d6146761d0f220 [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,
avm999634c1a6792020-08-31 21:30:42 +020022};
23
avm99963ad65e752020-09-01 00:13:59 +020024const specialOptions = [
25 'profileindicatoralt_months',
avm999630bc113a2020-09-07 13:02:11 +020026 'ccdarktheme_mode',
27 'ccdarktheme_switch_enabled',
avm999638e0c1002020-12-03 16:54:20 +010028 'ccdragndropfix',
avm99963ad65e752020-09-01 00:13:59 +020029];
30
avm999634c1a6792020-08-31 21:30:42 +020031const deprecatedOptions = [
32 'escalatethreads',
33 'movethreads',
34 'batchduplicate',
35];
36
37function isEmpty(obj) {
38 return Object.keys(obj).length === 0;
39}
40
41function cleanUpOptions(options) {
42 console.log('[cleanUpOptions] Previous options', options);
avm99963ad65e752020-09-01 00:13:59 +020043
44 if (typeof options !== 'object' || options === null) {
45 options = defaultOptions;
46 } else {
47 var ok = true;
48 for (const [opt, value] of Object.entries(defaultOptions)) {
49 if (!(opt in options)) {
50 ok = false;
51 options[opt] = value;
52 }
avm999634c1a6792020-08-31 21:30:42 +020053 }
54 }
55
56 console.log('[cleanUpOptions] New options', options);
57
58 if (!ok) {
59 chrome.storage.sync.set(options);
60 }
61
62 return options;
63}
avm999638e0c1002020-12-03 16:54:20 +010064
65// This method is based on the fact that when building the extension for Firefox
66// the browser_specific_settings.gecko entry is included.
67function isFirefox() {
68 var manifest = chrome.runtime.getManifest();
69 return manifest.browser_specific_settings !== undefined &&
70 manifest.browser_specific_settings.gecko !== undefined;
71}