blob: d4c4bd6e7b7e4591dce1e684811e01612667de2e [file] [log] [blame]
Adrià Vilanova Martínezba3eeba2021-07-25 12:22:02 +02001import {injectScript, injectStylesheet} from '../../common/contentScriptsUtils.js';
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +02002
avm99963b6f68b62021-08-12 23:13:06 +02003import AutoRefresh from './autoRefresh.js';
4
Adrià Vilanova Martínez2b871792021-06-09 12:35:06 +02005const SMEI_UNIFIED_PROFILES = 9;
6
avm999636d9c5fe2019-06-04 00:35:53 +02007chrome.storage.sync.get(null, function(items) {
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +02008 /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
Adrià Vilanova Martínezba3eeba2021-07-25 12:22:02 +02009 if (items.loaddrafts || 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
Adrià Vilanova Martínez2b871792021-06-09 12:35:06 +020017 if (items.disableunifiedprofiles) {
18 var index = startup[1][6].indexOf(SMEI_UNIFIED_PROFILES);
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +020019 if (index > -1) startup[1][6].splice(index, 1);
avm99963b38b7412020-12-11 17:59:02 +010020 }
21
avm99963b69eb3d2020-08-20 02:03:44 +020022 document.querySelector('html').setAttribute(
23 'data-startup', JSON.stringify(startup));
avm999636d9c5fe2019-06-04 00:35:53 +020024 }
avm999630bc113a2020-09-07 13:02:11 +020025
avm99963b6f68b62021-08-12 23:13:06 +020026 // Initialized here instead of in main.js so the first |ViewForumResponse|
27 // event is received if it happens when the page loads.
28 if (items.autorefreshlist)
avm99963fd222672021-08-12 23:23:01 +020029 window.TWPTAutoRefresh = new AutoRefresh();
avm99963b6f68b62021-08-12 23:13:06 +020030
avm999630bc113a2020-09-07 13:02:11 +020031 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});