blob: d30a113efa9d49bee86673f6c6fd5fbed1b745c3 [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ínez849ede62022-06-20 19:10:28 +02007const SMEI_NESTED_REPLIES = 15;
8const SMEI_RCE_THREAD_INTEROP = 22;
9
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020010getOptions(null).then(options => {
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +020011 /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +020012 if (options.loaddrafts || options.interopthreadpage) {
avm99963b69eb3d2020-08-20 02:03:44 +020013 var startup =
14 JSON.parse(document.querySelector('html').getAttribute('data-startup'));
avm99963c19497f2019-08-23 00:15:11 +020015
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020016 if (options.loaddrafts) {
avm99963c19497f2019-08-23 00:15:11 +020017 startup[4][13] = true;
18 }
19
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +020020 if (options.interopthreadpage) {
21 var index = startup[1][6].indexOf(SMEI_RCE_THREAD_INTEROP);
22
23 switch (options.interopthreadpage_mode) {
24 case 'previous':
25 if (index > -1) startup[1][6].splice(index, 1);
26 break;
27
28 case 'next':
29 if (index == -1) startup[1][6].push(SMEI_RCE_THREAD_INTEROP);
30 break;
31 }
32 }
33
34 if (options.nestedreplies) {
35 if (!startup[1][6].includes(SMEI_NESTED_REPLIES))
36 startup[1][6].push(SMEI_NESTED_REPLIES);
37 }
38
avm99963b69eb3d2020-08-20 02:03:44 +020039 document.querySelector('html').setAttribute(
40 'data-startup', JSON.stringify(startup));
avm999636d9c5fe2019-06-04 00:35:53 +020041 }
avm999630bc113a2020-09-07 13:02:11 +020042
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010043 // Initialized here instead of in main.js so the first event is received if it
44 // happens when the page loads.
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020045 window.TWPTAutoRefresh = new AutoRefresh();
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010046 window.TWPTExtraInfo = new ExtraInfo();
avm99963b6f68b62021-08-12 23:13:06 +020047
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020048 if (options.ccdarktheme) {
49 switch (options.ccdarktheme_mode) {
avm999630bc113a2020-09-07 13:02:11 +020050 case 'switch':
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020051 if (options.ccdarktheme_switch_status == true)
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020052 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'));
avm999630bc113a2020-09-07 13:02:11 +020053 break;
54
55 case 'system':
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020056 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'), {
avm999630bc113a2020-09-07 13:02:11 +020057 'media': '(prefers-color-scheme: dark)',
58 });
59 break;
60 }
61 }
Adrià Vilanova Martínez43ec2b92021-07-16 18:44:54 +020062
63 injectScript(chrome.runtime.getURL('xhrInterceptorInject.bundle.js'));
Adrià Vilanova Martínez4f56d562022-01-26 00:23:27 +010064 injectScript(chrome.runtime.getURL('extraInfoInject.bundle.js'));
avm999636d9c5fe2019-06-04 00:35:53 +020065});