blob: 294c6cdced01c984ca543860e9b54424f8a313bc [file] [log] [blame]
Adrià Vilanova Martínezba3eeba2021-07-25 12:22:02 +02001import {injectScript, injectStylesheet} from '../../common/contentScriptsUtils.js';
Adrià Vilanova Martínezc14e44a2023-03-09 19:28:03 +01002import MWI18nServer from '../../common/mainWorldI18n/Server.js';
Adrià Vilanova Martínezac2a5612022-12-27 21:51:40 +01003import MWOptionsWatcherServer from '../../common/mainWorldOptionsWatcher/Server.js';
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +02004import {getOptions} from '../../common/optionsUtils.js';
Adrià Vilanova Martínezac2a5612022-12-27 21:51:40 +01005import {kCSTarget, kMWTarget} from '../../xhrInterceptor/responseModifiers/index.js';
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +02006
avm99963b6f68b62021-08-12 23:13:06 +02007import AutoRefresh from './autoRefresh.js';
Adrià Vilanova Martínez0d92a0c2023-11-06 01:37:20 +01008import ExtraInfo from './extraInfo/index.js';
Adrià Vilanova Martínezd2344c42022-09-30 13:14:29 +02009import ThreadPageDesignWarning from './threadPageDesignWarning.js';
Adrià Vilanova Martíneze0d65f22022-11-06 18:49:35 +010010import WorkflowsImport from './workflows/import.js';
avm99963b6f68b62021-08-12 23:13:06 +020011
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +020012const SMEI_NESTED_REPLIES = 15;
13const SMEI_RCE_THREAD_INTEROP = 22;
14
Adrià Vilanova Martínez4b6ce462023-04-15 02:06:09 +020015// The servers should be available as soon as possible, since e.g. the XHRProxy
16// already sends a request to the optionsWatcher server as soon as it is
17// constructed.
18new MWOptionsWatcherServer(kCSTarget, kMWTarget);
19new MWI18nServer();
20
Adrià Vilanova Martínez102d54b2022-12-18 11:12:11 +010021injectScript(
22 chrome.runtime.getURL('xhrInterceptorInject.bundle.js'),
23 /* prepend = */ true);
Adrià Vilanova Martínez4e0cb182022-06-26 00:21:50 +020024injectScript(chrome.runtime.getURL('extraInfoInject.bundle.js'));
25
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020026getOptions(null).then(options => {
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +020027 /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
Adrià Vilanova Martínez32fd6422022-06-27 11:48:18 +020028 if (options.loaddrafts || options.interopthreadpage ||
29 options.nestedreplies) {
avm99963b69eb3d2020-08-20 02:03:44 +020030 var startup =
31 JSON.parse(document.querySelector('html').getAttribute('data-startup'));
avm99963c19497f2019-08-23 00:15:11 +020032
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020033 if (options.loaddrafts) {
avm99963c19497f2019-08-23 00:15:11 +020034 startup[4][13] = true;
35 }
36
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +020037 if (options.interopthreadpage) {
38 var index = startup[1][6].indexOf(SMEI_RCE_THREAD_INTEROP);
39
40 switch (options.interopthreadpage_mode) {
41 case 'previous':
42 if (index > -1) startup[1][6].splice(index, 1);
43 break;
44
45 case 'next':
46 if (index == -1) startup[1][6].push(SMEI_RCE_THREAD_INTEROP);
47 break;
48 }
49 }
50
51 if (options.nestedreplies) {
52 if (!startup[1][6].includes(SMEI_NESTED_REPLIES))
53 startup[1][6].push(SMEI_NESTED_REPLIES);
54 }
55
avm99963b69eb3d2020-08-20 02:03:44 +020056 document.querySelector('html').setAttribute(
57 'data-startup', JSON.stringify(startup));
avm999636d9c5fe2019-06-04 00:35:53 +020058 }
avm999630bc113a2020-09-07 13:02:11 +020059
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010060 // Initialized here instead of in main.js so the first event is received if it
61 // happens when the page loads.
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020062 window.TWPTAutoRefresh = new AutoRefresh();
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010063 window.TWPTExtraInfo = new ExtraInfo();
Adrià Vilanova Martínezd2344c42022-09-30 13:14:29 +020064 window.TWPTThreadPageDesignWarning = new ThreadPageDesignWarning();
Adrià Vilanova Martíneze0d65f22022-11-06 18:49:35 +010065 window.TWPTWorkflowsImport = new WorkflowsImport();
avm99963b6f68b62021-08-12 23:13:06 +020066
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020067 if (options.ccdarktheme) {
68 switch (options.ccdarktheme_mode) {
avm999630bc113a2020-09-07 13:02:11 +020069 case 'switch':
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020070 if (options.ccdarktheme_switch_status == true)
Adrià Vilanova Martínezddd30042023-11-01 22:54:17 +010071 injectStylesheet(chrome.runtime.getURL('ccDarkTheme.bundle.css'));
avm999630bc113a2020-09-07 13:02:11 +020072 break;
73
74 case 'system':
Adrià Vilanova Martínezddd30042023-11-01 22:54:17 +010075 injectStylesheet(chrome.runtime.getURL('ccDarkTheme.bundle.css'), {
avm999630bc113a2020-09-07 13:02:11 +020076 'media': '(prefers-color-scheme: dark)',
77 });
78 break;
79 }
80 }
Adrià Vilanova Martíneza2f79512022-07-10 15:32:32 +020081
82 if (options.uispacing) {
83 injectStylesheet(chrome.runtime.getURL('css/ui_spacing/shared.css'));
84 injectStylesheet(chrome.runtime.getURL('css/ui_spacing/console.css'));
85 }
avm999636d9c5fe2019-06-04 00:35:53 +020086});