blob: 1a67bca7f58dc1091ec32385122111a8b5b94d47 [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,
avm999634c1a6792020-08-31 21:30:42 +020021};
22
avm99963ad65e752020-09-01 00:13:59 +020023const specialOptions = [
24 'profileindicatoralt_months',
avm999630bc113a2020-09-07 13:02:11 +020025 'ccdarktheme_mode',
26 'ccdarktheme_switch_enabled',
avm99963ad65e752020-09-01 00:13:59 +020027];
28
avm999634c1a6792020-08-31 21:30:42 +020029const deprecatedOptions = [
30 'escalatethreads',
31 'movethreads',
32 'batchduplicate',
33];
34
35function isEmpty(obj) {
36 return Object.keys(obj).length === 0;
37}
38
39function cleanUpOptions(options) {
40 console.log('[cleanUpOptions] Previous options', options);
avm99963ad65e752020-09-01 00:13:59 +020041
42 if (typeof options !== 'object' || options === null) {
43 options = defaultOptions;
44 } else {
45 var ok = true;
46 for (const [opt, value] of Object.entries(defaultOptions)) {
47 if (!(opt in options)) {
48 ok = false;
49 options[opt] = value;
50 }
avm999634c1a6792020-08-31 21:30:42 +020051 }
52 }
53
54 console.log('[cleanUpOptions] New options', options);
55
56 if (!ok) {
57 chrome.storage.sync.set(options);
58 }
59
60 return options;
61}