blob: 4e8af629017f8241c18d17ed7bc6b68f9f1c8a63 [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';
5
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +02006getOptions(null).then(options => {
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +02007 /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
Adrià Vilanova Martínez2d22c4a2021-09-06 00:35:18 +02008 if (options.loaddrafts) {
avm99963b69eb3d2020-08-20 02:03:44 +02009 var startup =
10 JSON.parse(document.querySelector('html').getAttribute('data-startup'));
avm99963c19497f2019-08-23 00:15:11 +020011
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020012 if (options.loaddrafts) {
avm99963c19497f2019-08-23 00:15:11 +020013 startup[4][13] = true;
14 }
15
avm99963b69eb3d2020-08-20 02:03:44 +020016 document.querySelector('html').setAttribute(
17 'data-startup', JSON.stringify(startup));
avm999636d9c5fe2019-06-04 00:35:53 +020018 }
avm999630bc113a2020-09-07 13:02:11 +020019
avm99963b6f68b62021-08-12 23:13:06 +020020 // Initialized here instead of in main.js so the first |ViewForumResponse|
21 // event is received if it happens when the page loads.
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020022 window.TWPTAutoRefresh = new AutoRefresh();
avm99963b6f68b62021-08-12 23:13:06 +020023
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020024 if (options.ccdarktheme) {
25 switch (options.ccdarktheme_mode) {
avm999630bc113a2020-09-07 13:02:11 +020026 case 'switch':
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020027 if (options.ccdarktheme_switch_status == true)
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020028 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'));
avm999630bc113a2020-09-07 13:02:11 +020029 break;
30
31 case 'system':
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020032 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'), {
avm999630bc113a2020-09-07 13:02:11 +020033 'media': '(prefers-color-scheme: dark)',
34 });
35 break;
36 }
37 }
Adrià Vilanova Martínez43ec2b92021-07-16 18:44:54 +020038
39 injectScript(chrome.runtime.getURL('xhrInterceptorInject.bundle.js'));
avm999636d9c5fe2019-06-04 00:35:53 +020040});