blob: b3417fed14f765a595268fa358710cea905f8c23 [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';
Adrià Vilanova Martíneze0d65f22022-11-06 18:49:35 +01007import WorkflowsImport from './workflows/import.js';
avm99963b6f68b62021-08-12 23:13:06 +02008
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +02009const SMEI_NESTED_REPLIES = 15;
10const SMEI_RCE_THREAD_INTEROP = 22;
11
Adrià Vilanova Martínez4e0cb182022-06-26 00:21:50 +020012injectScript(chrome.runtime.getURL('xhrInterceptorInject.bundle.js'));
13injectScript(chrome.runtime.getURL('extraInfoInject.bundle.js'));
14
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020015getOptions(null).then(options => {
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +020016 /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
Adrià Vilanova Martínez32fd6422022-06-27 11:48:18 +020017 if (options.loaddrafts || options.interopthreadpage ||
18 options.nestedreplies) {
avm99963b69eb3d2020-08-20 02:03:44 +020019 var startup =
20 JSON.parse(document.querySelector('html').getAttribute('data-startup'));
avm99963c19497f2019-08-23 00:15:11 +020021
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020022 if (options.loaddrafts) {
avm99963c19497f2019-08-23 00:15:11 +020023 startup[4][13] = true;
24 }
25
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +020026 if (options.interopthreadpage) {
27 var index = startup[1][6].indexOf(SMEI_RCE_THREAD_INTEROP);
28
29 switch (options.interopthreadpage_mode) {
30 case 'previous':
31 if (index > -1) startup[1][6].splice(index, 1);
32 break;
33
34 case 'next':
35 if (index == -1) startup[1][6].push(SMEI_RCE_THREAD_INTEROP);
36 break;
37 }
38 }
39
40 if (options.nestedreplies) {
41 if (!startup[1][6].includes(SMEI_NESTED_REPLIES))
42 startup[1][6].push(SMEI_NESTED_REPLIES);
43 }
44
avm99963b69eb3d2020-08-20 02:03:44 +020045 document.querySelector('html').setAttribute(
46 'data-startup', JSON.stringify(startup));
avm999636d9c5fe2019-06-04 00:35:53 +020047 }
avm999630bc113a2020-09-07 13:02:11 +020048
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010049 // Initialized here instead of in main.js so the first event is received if it
50 // happens when the page loads.
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020051 window.TWPTAutoRefresh = new AutoRefresh();
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010052 window.TWPTExtraInfo = new ExtraInfo();
Adrià Vilanova Martínezd2344c42022-09-30 13:14:29 +020053 window.TWPTThreadPageDesignWarning = new ThreadPageDesignWarning();
Adrià Vilanova Martíneze0d65f22022-11-06 18:49:35 +010054 window.TWPTWorkflowsImport = new WorkflowsImport();
avm99963b6f68b62021-08-12 23:13:06 +020055
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020056 if (options.ccdarktheme) {
57 switch (options.ccdarktheme_mode) {
avm999630bc113a2020-09-07 13:02:11 +020058 case 'switch':
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020059 if (options.ccdarktheme_switch_status == true)
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020060 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'));
avm999630bc113a2020-09-07 13:02:11 +020061 break;
62
63 case 'system':
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020064 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'), {
avm999630bc113a2020-09-07 13:02:11 +020065 'media': '(prefers-color-scheme: dark)',
66 });
67 break;
68 }
69 }
Adrià Vilanova Martíneza2f79512022-07-10 15:32:32 +020070
71 if (options.uispacing) {
72 injectStylesheet(chrome.runtime.getURL('css/ui_spacing/shared.css'));
73 injectStylesheet(chrome.runtime.getURL('css/ui_spacing/console.css'));
74 }
avm999636d9c5fe2019-06-04 00:35:53 +020075});