blob: c4a3d740c717490746cc8e7ddcfb63ab9bf7e2cf [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 ||
Adrià Vilanova Martínez66dba7c2024-05-15 22:38:20 +020014 options.nestedreplies || options.fixpekb269560789) {
avm99963b69eb3d2020-08-20 02:03:44 +020015 var startup =
Adrià Vilanova Martínez66dba7c2024-05-15 22:38:20 +020016 JSON.parse(document.querySelector('html').getAttribute('data-startup'));
17
18 if (options.fixpekb269560789) {
19 if (startup[1]?.[1]?.[8]?.[7]) {
20 delete startup[1]?.[1]?.[8]?.[7];
21 }
22 }
avm99963c19497f2019-08-23 00:15:11 +020023
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020024 if (options.loaddrafts) {
avm99963c19497f2019-08-23 00:15:11 +020025 startup[4][13] = true;
26 }
27
Adrià Vilanova Martínez849ede62022-06-20 19:10:28 +020028 if (options.interopthreadpage) {
29 var index = startup[1][6].indexOf(SMEI_RCE_THREAD_INTEROP);
30
31 switch (options.interopthreadpage_mode) {
32 case 'previous':
33 if (index > -1) startup[1][6].splice(index, 1);
34 break;
35
36 case 'next':
37 if (index == -1) startup[1][6].push(SMEI_RCE_THREAD_INTEROP);
38 break;
39 }
40 }
41
42 if (options.nestedreplies) {
43 if (!startup[1][6].includes(SMEI_NESTED_REPLIES))
44 startup[1][6].push(SMEI_NESTED_REPLIES);
45 }
46
avm99963b69eb3d2020-08-20 02:03:44 +020047 document.querySelector('html').setAttribute(
48 'data-startup', JSON.stringify(startup));
avm999636d9c5fe2019-06-04 00:35:53 +020049 }
avm999630bc113a2020-09-07 13:02:11 +020050
Adrià Vilanova Martínez7e8796c2022-01-23 21:46:46 +010051 // Initialized here instead of in main.js so the first event is received if it
52 // happens when the page loads.
Adrià Vilanova Martínezd2344c42022-09-30 13:14:29 +020053 window.TWPTThreadPageDesignWarning = new ThreadPageDesignWarning();
Adrià Vilanova Martíneze0d65f22022-11-06 18:49:35 +010054 window.TWPTWorkflowsImport = new WorkflowsImport();
avm99963b6f68b62021-08-12 23:13:06 +020055
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020056 if (options.ccdarktheme) {
57 switch (options.ccdarktheme_mode) {
avm999630bc113a2020-09-07 13:02:11 +020058 case 'switch':
Adrià Vilanova Martínezd269c622021-09-04 18:35:55 +020059 if (options.ccdarktheme_switch_status == true)
Adrià Vilanova Martínezddd30042023-11-01 22:54:17 +010060 injectStylesheet(chrome.runtime.getURL('ccDarkTheme.bundle.css'));
avm999630bc113a2020-09-07 13:02:11 +020061 break;
62
63 case 'system':
Adrià Vilanova Martínezddd30042023-11-01 22:54:17 +010064 injectStylesheet(chrome.runtime.getURL('ccDarkTheme.bundle.css'), {
avm999630bc113a2020-09-07 13:02:11 +020065 'media': '(prefers-color-scheme: dark)',
66 });
67 break;
68 }
69 }
Adrià Vilanova Martíneza2f79512022-07-10 15:32:32 +020070
71 if (options.uispacing) {
72 injectStylesheet(chrome.runtime.getURL('css/ui_spacing/shared.css'));
73 injectStylesheet(chrome.runtime.getURL('css/ui_spacing/console.css'));
74 }
Adrià Vilanova Martínez72a4ea42024-02-09 22:35:32 +010075
Adrià Vilanova Martínez66836fd2024-05-04 22:43:06 +020076 const flattenThreadsReplyActionHandler =
77 new FlattenThreadsReplyActionHandler(options);
Adrià Vilanova Martínez72a4ea42024-02-09 22:35:32 +010078 flattenThreadsReplyActionHandler.handleIfApplicable();
avm999636d9c5fe2019-06-04 00:35:53 +020079});