blob: a0640ba4189d5cd4d5d1fe39bb7a7df0b568f5d0 [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_NESTED_REPLIES = 15;
9const SMEI_RCE_THREAD_INTEROP = 22;
10
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020011getOptions(null).then(options => {
Adrià Vilanova Martínezd2ac4ce2021-06-11 16:41:43 +020012 /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */
Adrià Vilanova Martínez32fd6422022-06-27 11:48:18 +020013 if (options.loaddrafts || options.interopthreadpage ||
14 options.nestedreplies) {
avm99963b69eb3d2020-08-20 02:03:44 +020015 var startup =
16 JSON.parse(document.querySelector('html').getAttribute('data-startup'));
avm99963c19497f2019-08-23 00:15:11 +020017
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020018 if (options.loaddrafts) {
avm99963c19497f2019-08-23 00:15:11 +020019 startup[4][13] = true;
20 }
21
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +020022 if (options.interopthreadpage) {
23 var index = startup[1][6].indexOf(SMEI_RCE_THREAD_INTEROP);
24
25 switch (options.interopthreadpage_mode) {
26 case 'previous':
27 if (index > -1) startup[1][6].splice(index, 1);
28 break;
29
30 case 'next':
31 if (index == -1) startup[1][6].push(SMEI_RCE_THREAD_INTEROP);
32 break;
33 }
34 }
35
36 if (options.nestedreplies) {
37 if (!startup[1][6].includes(SMEI_NESTED_REPLIES))
38 startup[1][6].push(SMEI_NESTED_REPLIES);
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});