blob: f3646263ee91e4313181def4f53ed715830ac57d [file] [log] [blame]
Adrià Vilanova Martínezba3eeba2021-07-25 12:22:02 +02001import {injectScript, injectStylesheet} from '../../common/contentScriptsUtils.js';
Adrià Vilanova Martínezac2a5612022-12-27 21:51:40 +01002import MWOptionsWatcherServer from '../../common/mainWorldOptionsWatcher/Server.js';
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +02003import {getOptions} from '../../common/optionsUtils.js';
Adrià Vilanova Martínezac2a5612022-12-27 21:51:40 +01004import {kCSTarget, kMWTarget} from '../../xhrInterceptor/responseModifiers/index.js';
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +02005
avm99963b6f68b62021-08-12 23:13:06 +02006import AutoRefresh from './autoRefresh.js';
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +01007import ExtraInfo from './extraInfo.js';
Adrià Vilanova Martínezd2344c42022-09-30 13:14:29 +02008import ThreadPageDesignWarning from './threadPageDesignWarning.js';
Adrià Vilanova Martíneze0d65f22022-11-06 18:49:35 +01009import WorkflowsImport from './workflows/import.js';
avm99963b6f68b62021-08-12 23:13:06 +020010
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +020011const SMEI_NESTED_REPLIES = 15;
12const SMEI_RCE_THREAD_INTEROP = 22;
13
Adrià Vilanova Martínez102d54b2022-12-18 11:12:11 +010014injectScript(
15 chrome.runtime.getURL('xhrInterceptorInject.bundle.js'),
16 /* prepend = */ true);
Adrià Vilanova Martínez4e0cb182022-06-26 00:21:50 +020017injectScript(chrome.runtime.getURL('extraInfoInject.bundle.js'));
18
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020019getOptions(null).then(options => {
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +020020 /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
Adrià Vilanova Martínez32fd6422022-06-27 11:48:18 +020021 if (options.loaddrafts || options.interopthreadpage ||
22 options.nestedreplies) {
avm99963b69eb3d2020-08-20 02:03:44 +020023 var startup =
24 JSON.parse(document.querySelector('html').getAttribute('data-startup'));
avm99963c19497f2019-08-23 00:15:11 +020025
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020026 if (options.loaddrafts) {
avm99963c19497f2019-08-23 00:15:11 +020027 startup[4][13] = true;
28 }
29
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +020030 if (options.interopthreadpage) {
31 var index = startup[1][6].indexOf(SMEI_RCE_THREAD_INTEROP);
32
33 switch (options.interopthreadpage_mode) {
34 case 'previous':
35 if (index > -1) startup[1][6].splice(index, 1);
36 break;
37
38 case 'next':
39 if (index == -1) startup[1][6].push(SMEI_RCE_THREAD_INTEROP);
40 break;
41 }
42 }
43
44 if (options.nestedreplies) {
45 if (!startup[1][6].includes(SMEI_NESTED_REPLIES))
46 startup[1][6].push(SMEI_NESTED_REPLIES);
47 }
48
avm99963b69eb3d2020-08-20 02:03:44 +020049 document.querySelector('html').setAttribute(
50 'data-startup', JSON.stringify(startup));
avm999636d9c5fe2019-06-04 00:35:53 +020051 }
avm999630bc113a2020-09-07 13:02:11 +020052
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010053 // Initialized here instead of in main.js so the first event is received if it
54 // happens when the page loads.
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020055 window.TWPTAutoRefresh = new AutoRefresh();
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010056 window.TWPTExtraInfo = new ExtraInfo();
Adrià Vilanova Martínezd2344c42022-09-30 13:14:29 +020057 window.TWPTThreadPageDesignWarning = new ThreadPageDesignWarning();
Adrià Vilanova Martíneze0d65f22022-11-06 18:49:35 +010058 window.TWPTWorkflowsImport = new WorkflowsImport();
avm99963b6f68b62021-08-12 23:13:06 +020059
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020060 if (options.ccdarktheme) {
61 switch (options.ccdarktheme_mode) {
avm999630bc113a2020-09-07 13:02:11 +020062 case 'switch':
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020063 if (options.ccdarktheme_switch_status == true)
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020064 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'));
avm999630bc113a2020-09-07 13:02:11 +020065 break;
66
67 case 'system':
Adrià Vilanova Martínez3465e772021-07-11 19:18:41 +020068 injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'), {
avm999630bc113a2020-09-07 13:02:11 +020069 'media': '(prefers-color-scheme: dark)',
70 });
71 break;
72 }
73 }
Adrià Vilanova Martíneza2f79512022-07-10 15:32:32 +020074
75 if (options.uispacing) {
76 injectStylesheet(chrome.runtime.getURL('css/ui_spacing/shared.css'));
77 injectStylesheet(chrome.runtime.getURL('css/ui_spacing/console.css'));
78 }
Adrià Vilanova Martínezac2a5612022-12-27 21:51:40 +010079
80 new MWOptionsWatcherServer(kCSTarget, kMWTarget);
avm999636d9c5fe2019-06-04 00:35:53 +020081});