blob: f0c43d8a1738f4b392cac7b938f1a0e67eceba34 [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';
Adrià Vilanova Martínezd2344c42022-09-30 13:14:29 +02006import ThreadPageDesignWarning from './threadPageDesignWarning.js';
avm99963b6f68b62021-08-12 23:13:06 +02007
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +02008const SMEI_NESTED_REPLIES = 15;
9const SMEI_RCE_THREAD_INTEROP = 22;
10
Adrià Vilanova Martínez4e0cb182022-06-26 00:21:50 +020011injectScript(chrome.runtime.getURL('xhrInterceptorInject.bundle.js'));
12injectScript(chrome.runtime.getURL('extraInfoInject.bundle.js'));
13
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020014getOptions(null).then(options => {
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +020015 /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
Adrià Vilanova Martínez32fd6422022-06-27 11:48:18 +020016 if (options.loaddrafts || options.interopthreadpage ||
17 options.nestedreplies) {
avm99963b69eb3d2020-08-20 02:03:44 +020018 var startup =
19 JSON.parse(document.querySelector('html').getAttribute('data-startup'));
avm99963c19497f2019-08-23 00:15:11 +020020
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020021 if (options.loaddrafts) {
avm99963c19497f2019-08-23 00:15:11 +020022 startup[4][13] = true;
23 }
24
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +020025 if (options.interopthreadpage) {
26 var index = startup[1][6].indexOf(SMEI_RCE_THREAD_INTEROP);
27
28 switch (options.interopthreadpage_mode) {
29 case 'previous':
30 if (index > -1) startup[1][6].splice(index, 1);
31 break;
32
33 case 'next':
34 if (index == -1) startup[1][6].push(SMEI_RCE_THREAD_INTEROP);
35 break;
36 }
37 }
38
39 if (options.nestedreplies) {
40 if (!startup[1][6].includes(SMEI_NESTED_REPLIES))
41 startup[1][6].push(SMEI_NESTED_REPLIES);
42 }
43
avm99963b69eb3d2020-08-20 02:03:44 +020044 document.querySelector('html').setAttribute(
45 'data-startup', JSON.stringify(startup));
avm999636d9c5fe2019-06-04 00:35:53 +020046 }
avm999630bc113a2020-09-07 13:02:11 +020047
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010048 // Initialized here instead of in main.js so the first event is received if it
49 // happens when the page loads.
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020050 window.TWPTAutoRefresh = new AutoRefresh();
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010051 window.TWPTExtraInfo = new ExtraInfo();
Adrià Vilanova Martínezd2344c42022-09-30 13:14:29 +020052 window.TWPTThreadPageDesignWarning = new ThreadPageDesignWarning();
avm99963b6f68b62021-08-12 23:13:06 +020053
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020054 if (options.ccdarktheme) {
55 switch (options.ccdarktheme_mode) {
avm999630bc113a2020-09-07 13:02:11 +020056 case 'switch':
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020057 if (options.ccdarktheme_switch_status == true)
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020058 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'));
avm999630bc113a2020-09-07 13:02:11 +020059 break;
60
61 case 'system':
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020062 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'), {
avm999630bc113a2020-09-07 13:02:11 +020063 'media': '(prefers-color-scheme: dark)',
64 });
65 break;
66 }
67 }
Adrià Vilanova Martíneza2f79512022-07-10 15:32:32 +020068
69 if (options.uispacing) {
70 injectStylesheet(chrome.runtime.getURL('css/ui_spacing/shared.css'));
71 injectStylesheet(chrome.runtime.getURL('css/ui_spacing/console.css'));
72 }
avm999636d9c5fe2019-06-04 00:35:53 +020073});