blob: 1bb6a3f4d9a96241c7ef6d364eb584f1ebbd5293 [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ínez4e0cb182022-06-26 00:21:50 +020010injectScript(chrome.runtime.getURL('xhrInterceptorInject.bundle.js'));
11injectScript(chrome.runtime.getURL('extraInfoInject.bundle.js'));
12
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020013getOptions(null).then(options => {
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +020014 /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
Adrià Vilanova Martínez32fd6422022-06-27 11:48:18 +020015 if (options.loaddrafts || options.interopthreadpage ||
16 options.nestedreplies) {
avm99963b69eb3d2020-08-20 02:03:44 +020017 var startup =
18 JSON.parse(document.querySelector('html').getAttribute('data-startup'));
avm99963c19497f2019-08-23 00:15:11 +020019
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020020 if (options.loaddrafts) {
avm99963c19497f2019-08-23 00:15:11 +020021 startup[4][13] = true;
22 }
23
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +020024 if (options.interopthreadpage) {
25 var index = startup[1][6].indexOf(SMEI_RCE_THREAD_INTEROP);
26
27 switch (options.interopthreadpage_mode) {
28 case 'previous':
29 if (index > -1) startup[1][6].splice(index, 1);
30 break;
31
32 case 'next':
33 if (index == -1) startup[1][6].push(SMEI_RCE_THREAD_INTEROP);
34 break;
35 }
36 }
37
38 if (options.nestedreplies) {
39 if (!startup[1][6].includes(SMEI_NESTED_REPLIES))
40 startup[1][6].push(SMEI_NESTED_REPLIES);
41 }
42
avm99963b69eb3d2020-08-20 02:03:44 +020043 document.querySelector('html').setAttribute(
44 'data-startup', JSON.stringify(startup));
avm999636d9c5fe2019-06-04 00:35:53 +020045 }
avm999630bc113a2020-09-07 13:02:11 +020046
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010047 // Initialized here instead of in main.js so the first event is received if it
48 // happens when the page loads.
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020049 window.TWPTAutoRefresh = new AutoRefresh();
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010050 window.TWPTExtraInfo = new ExtraInfo();
avm99963b6f68b62021-08-12 23:13:06 +020051
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020052 if (options.ccdarktheme) {
53 switch (options.ccdarktheme_mode) {
avm999630bc113a2020-09-07 13:02:11 +020054 case 'switch':
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020055 if (options.ccdarktheme_switch_status == true)
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020056 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'));
avm999630bc113a2020-09-07 13:02:11 +020057 break;
58
59 case 'system':
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020060 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'), {
avm999630bc113a2020-09-07 13:02:11 +020061 'media': '(prefers-color-scheme: dark)',
62 });
63 break;
64 }
65 }
avm999636d9c5fe2019-06-04 00:35:53 +020066});