blob: 063f58ab6d6a068e11c5faaf7af71f85324c90ff [file] [log] [blame]
Adrià Vilanova Martínez66836fd2024-05-04 22:43:06 +02001import {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
Adrià Vilanova Martínez72a4ea42024-02-09 22:35:32 +01004import FlattenThreadsReplyActionHandler from './flattenThreads/replyActionHandler.js';
Adrià Vilanova Martínezd2344c42022-09-30 13:14:29 +02005import ThreadPageDesignWarning from './threadPageDesignWarning.js';
Adrià Vilanova Martíneze0d65f22022-11-06 18:49:35 +01006import WorkflowsImport from './workflows/import.js';
avm99963b6f68b62021-08-12 23:13:06 +02007
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +02008const SMEI_RCE_THREAD_INTEROP = 22;
9
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020010getOptions(null).then(options => {
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +020011 /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
Adrià Vilanova Martínez32fd6422022-06-27 11:48:18 +020012 if (options.loaddrafts || options.interopthreadpage ||
Adrià Vilanova Martínez8423dfd2024-05-16 22:15:55 +020013 options.fixpekb269560789) {
avm99963b69eb3d2020-08-20 02:03:44 +020014 var startup =
Adrià Vilanova Martínez8423dfd2024-05-16 22:15:55 +020015 JSON.parse(document.querySelector('html').getAttribute('data-startup'));
Adrià Vilanova Martínez66dba7c2024-05-15 22:38:20 +020016
17 if (options.fixpekb269560789) {
18 if (startup[1]?.[1]?.[8]?.[7]) {
19 delete startup[1]?.[1]?.[8]?.[7];
20 }
21 }
avm99963c19497f2019-08-23 00:15:11 +020022
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020023 if (options.loaddrafts) {
avm99963c19497f2019-08-23 00:15:11 +020024 startup[4][13] = true;
25 }
26
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +020027 if (options.interopthreadpage) {
28 var index = startup[1][6].indexOf(SMEI_RCE_THREAD_INTEROP);
29
30 switch (options.interopthreadpage_mode) {
31 case 'previous':
32 if (index > -1) startup[1][6].splice(index, 1);
33 break;
34
35 case 'next':
36 if (index == -1) startup[1][6].push(SMEI_RCE_THREAD_INTEROP);
37 break;
38 }
39 }
40
avm99963b69eb3d2020-08-20 02:03:44 +020041 document.querySelector('html').setAttribute(
42 'data-startup', JSON.stringify(startup));
avm999636d9c5fe2019-06-04 00:35:53 +020043 }
avm999630bc113a2020-09-07 13:02:11 +020044
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010045 // Initialized here instead of in main.js so the first event is received if it
46 // happens when the page loads.
Adrià Vilanova Martínezd2344c42022-09-30 13:14:29 +020047 window.TWPTThreadPageDesignWarning = new ThreadPageDesignWarning();
Adrià Vilanova Martíneze0d65f22022-11-06 18:49:35 +010048 window.TWPTWorkflowsImport = new WorkflowsImport();
avm99963b6f68b62021-08-12 23:13:06 +020049
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020050 if (options.ccdarktheme) {
51 switch (options.ccdarktheme_mode) {
avm999630bc113a2020-09-07 13:02:11 +020052 case 'switch':
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020053 if (options.ccdarktheme_switch_status == true)
Adrià Vilanova Martínezddd30042023-11-01 22:54:17 +010054 injectStylesheet(chrome.runtime.getURL('ccDarkTheme.bundle.css'));
avm999630bc113a2020-09-07 13:02:11 +020055 break;
56
57 case 'system':
Adrià Vilanova Martínezddd30042023-11-01 22:54:17 +010058 injectStylesheet(chrome.runtime.getURL('ccDarkTheme.bundle.css'), {
avm999630bc113a2020-09-07 13:02:11 +020059 'media': '(prefers-color-scheme: dark)',
60 });
61 break;
62 }
63 }
Adrià Vilanova Martíneza2f79512022-07-10 15:32:32 +020064
65 if (options.uispacing) {
66 injectStylesheet(chrome.runtime.getURL('css/ui_spacing/shared.css'));
67 injectStylesheet(chrome.runtime.getURL('css/ui_spacing/console.css'));
68 }
Adrià Vilanova Martínez72a4ea42024-02-09 22:35:32 +010069
Adrià Vilanova Martínez66836fd2024-05-04 22:43:06 +020070 const flattenThreadsReplyActionHandler =
71 new FlattenThreadsReplyActionHandler(options);
Adrià Vilanova Martínez72a4ea42024-02-09 22:35:32 +010072 flattenThreadsReplyActionHandler.handleIfApplicable();
avm999636d9c5fe2019-06-04 00:35:53 +020073});