blob: 9c14a434061c51c76df4b75939c3004096d43238 [file] [log] [blame]
Adrià Vilanova Martínez43ec2b92021-07-16 18:44:54 +02001import {injectStylesheet, injectScript} from '../../common/contentScriptsUtils.js';
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +02002
Adrià Vilanova Martínez2b871792021-06-09 12:35:06 +02003const SMEI_SORT_DIRECTION = 8;
4const SMEI_UNIFIED_PROFILES = 9;
5
avm999636d9c5fe2019-06-04 00:35:53 +02006chrome.storage.sync.get(null, function(items) {
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +02007 /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
8 if (items.loaddrafts || items.smei_sortdirection ||
9 items.disableunifiedprofiles) {
avm99963b69eb3d2020-08-20 02:03:44 +020010 var startup =
11 JSON.parse(document.querySelector('html').getAttribute('data-startup'));
avm99963c19497f2019-08-23 00:15:11 +020012
13 if (items.loaddrafts) {
14 startup[4][13] = true;
15 }
16
avm99963b38b7412020-12-11 17:59:02 +010017 if (items.smei_sortdirection) {
Adrià Vilanova Martínez2b871792021-06-09 12:35:06 +020018 if (!startup[1][6].includes(SMEI_SORT_DIRECTION))
19 startup[1][6].push(SMEI_SORT_DIRECTION);
20 }
21
22 if (items.disableunifiedprofiles) {
23 var index = startup[1][6].indexOf(SMEI_UNIFIED_PROFILES);
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +020024 if (index > -1) startup[1][6].splice(index, 1);
avm99963b38b7412020-12-11 17:59:02 +010025 }
26
avm99963b69eb3d2020-08-20 02:03:44 +020027 document.querySelector('html').setAttribute(
28 'data-startup', JSON.stringify(startup));
avm999636d9c5fe2019-06-04 00:35:53 +020029 }
avm999630bc113a2020-09-07 13:02:11 +020030
31 if (items.ccdarktheme) {
32 switch (items.ccdarktheme_mode) {
33 case 'switch':
34 if (items.ccdarktheme_switch_status == true)
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020035 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'));
avm999630bc113a2020-09-07 13:02:11 +020036 break;
37
38 case 'system':
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020039 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'), {
avm999630bc113a2020-09-07 13:02:11 +020040 'media': '(prefers-color-scheme: dark)',
41 });
42 break;
43 }
44 }
Adrià Vilanova Martínez43ec2b92021-07-16 18:44:54 +020045
46 injectScript(chrome.runtime.getURL('xhrInterceptorInject.bundle.js'));
avm999636d9c5fe2019-06-04 00:35:53 +020047});