blob: 7abbeaa189377bb2dfa41504cf50adf2e3c428f7 [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ínez7e8796c2022-01-23 21:46:46 +01008import ExtraInfo from './extraInfo.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ínez102d54b2022-12-18 11:12:11 +010015injectScript(
16 chrome.runtime.getURL('xhrInterceptorInject.bundle.js'),
17 /* prepend = */ true);
Adrià Vilanova Martínez4e0cb182022-06-26 00:21:50 +020018injectScript(chrome.runtime.getURL('extraInfoInject.bundle.js'));
19
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020020getOptions(null).then(options => {
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +020021 /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
Adrià Vilanova Martínez32fd6422022-06-27 11:48:18 +020022 if (options.loaddrafts || options.interopthreadpage ||
23 options.nestedreplies) {
avm99963b69eb3d2020-08-20 02:03:44 +020024 var startup =
25 JSON.parse(document.querySelector('html').getAttribute('data-startup'));
avm99963c19497f2019-08-23 00:15:11 +020026
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020027 if (options.loaddrafts) {
avm99963c19497f2019-08-23 00:15:11 +020028 startup[4][13] = true;
29 }
30
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +020031 if (options.interopthreadpage) {
32 var index = startup[1][6].indexOf(SMEI_RCE_THREAD_INTEROP);
33
34 switch (options.interopthreadpage_mode) {
35 case 'previous':
36 if (index > -1) startup[1][6].splice(index, 1);
37 break;
38
39 case 'next':
40 if (index == -1) startup[1][6].push(SMEI_RCE_THREAD_INTEROP);
41 break;
42 }
43 }
44
45 if (options.nestedreplies) {
46 if (!startup[1][6].includes(SMEI_NESTED_REPLIES))
47 startup[1][6].push(SMEI_NESTED_REPLIES);
48 }
49
avm99963b69eb3d2020-08-20 02:03:44 +020050 document.querySelector('html').setAttribute(
51 'data-startup', JSON.stringify(startup));
avm999636d9c5fe2019-06-04 00:35:53 +020052 }
avm999630bc113a2020-09-07 13:02:11 +020053
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010054 // Initialized here instead of in main.js so the first event is received if it
55 // happens when the page loads.
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020056 window.TWPTAutoRefresh = new AutoRefresh();
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010057 window.TWPTExtraInfo = new ExtraInfo();
Adrià Vilanova Martínezd2344c42022-09-30 13:14:29 +020058 window.TWPTThreadPageDesignWarning = new ThreadPageDesignWarning();
Adrià Vilanova Martíneze0d65f22022-11-06 18:49:35 +010059 window.TWPTWorkflowsImport = new WorkflowsImport();
avm99963b6f68b62021-08-12 23:13:06 +020060
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020061 if (options.ccdarktheme) {
62 switch (options.ccdarktheme_mode) {
avm999630bc113a2020-09-07 13:02:11 +020063 case 'switch':
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020064 if (options.ccdarktheme_switch_status == true)
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020065 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'));
avm999630bc113a2020-09-07 13:02:11 +020066 break;
67
68 case 'system':
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020069 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'), {
avm999630bc113a2020-09-07 13:02:11 +020070 'media': '(prefers-color-scheme: dark)',
71 });
72 break;
73 }
74 }
Adrià Vilanova Martíneza2f79512022-07-10 15:32:32 +020075
76 if (options.uispacing) {
77 injectStylesheet(chrome.runtime.getURL('css/ui_spacing/shared.css'));
78 injectStylesheet(chrome.runtime.getURL('css/ui_spacing/console.css'));
79 }
Adrià Vilanova Martínezac2a5612022-12-27 21:51:40 +010080
81 new MWOptionsWatcherServer(kCSTarget, kMWTarget);
Adrià Vilanova Martínezc14e44a2023-03-09 19:28:03 +010082 new MWI18nServer();
avm999636d9c5fe2019-06-04 00:35:53 +020083});