blob: 250df78722000eec4f3317c5604cd446e10cf087 [file] [log] [blame]
Adrià Vilanova Martínezba3eeba2021-07-25 12:22:02 +02001import {injectScript, injectStylesheet} from '../../common/contentScriptsUtils.js';
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +02002import {getOptions} from '../../common/optionsUtils.js';
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +02003
avm99963b6f68b62021-08-12 23:13:06 +02004import AutoRefresh from './autoRefresh.js';
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +01005import ExtraInfo from './extraInfo.js';
avm99963b6f68b62021-08-12 23:13:06 +02006
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +02007getOptions(null).then(options => {
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +02008 /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
Adrià Vilanova Martínez2d22c4a2021-09-06 00:35:18 +02009 if (options.loaddrafts) {
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
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020013 if (options.loaddrafts) {
avm99963c19497f2019-08-23 00:15:11 +020014 startup[4][13] = true;
15 }
16
avm99963b69eb3d2020-08-20 02:03:44 +020017 document.querySelector('html').setAttribute(
18 'data-startup', JSON.stringify(startup));
avm999636d9c5fe2019-06-04 00:35:53 +020019 }
avm999630bc113a2020-09-07 13:02:11 +020020
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010021 // Initialized here instead of in main.js so the first event is received if it
22 // happens when the page loads.
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020023 window.TWPTAutoRefresh = new AutoRefresh();
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010024 window.TWPTExtraInfo = new ExtraInfo();
avm99963b6f68b62021-08-12 23:13:06 +020025
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020026 if (options.ccdarktheme) {
27 switch (options.ccdarktheme_mode) {
avm999630bc113a2020-09-07 13:02:11 +020028 case 'switch':
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020029 if (options.ccdarktheme_switch_status == true)
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020030 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'));
avm999630bc113a2020-09-07 13:02:11 +020031 break;
32
33 case 'system':
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020034 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'), {
avm999630bc113a2020-09-07 13:02:11 +020035 'media': '(prefers-color-scheme: dark)',
36 });
37 break;
38 }
39 }
Adrià Vilanova Martínez43ec2b92021-07-16 18:44:54 +020040
41 injectScript(chrome.runtime.getURL('xhrInterceptorInject.bundle.js'));
Adrià Vilanova Martínez4f56d562022-01-26 00:23:27 +010042 injectScript(chrome.runtime.getURL('extraInfoInject.bundle.js'));
avm999636d9c5fe2019-06-04 00:35:53 +020043});