Adrià Vilanova Martínez | ba3eeba | 2021-07-25 12:22:02 +0200 | [diff] [blame] | 1 | import {injectScript, injectStylesheet} from '../../common/contentScriptsUtils.js'; |
Adrià Vilanova Martínez | c14e44a | 2023-03-09 19:28:03 +0100 | [diff] [blame] | 2 | import MWI18nServer from '../../common/mainWorldI18n/Server.js'; |
Adrià Vilanova Martínez | ac2a561 | 2022-12-27 21:51:40 +0100 | [diff] [blame] | 3 | import MWOptionsWatcherServer from '../../common/mainWorldOptionsWatcher/Server.js'; |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 4 | import {getOptions} from '../../common/optionsUtils.js'; |
Adrià Vilanova Martínez | ac2a561 | 2022-12-27 21:51:40 +0100 | [diff] [blame] | 5 | import {kCSTarget, kMWTarget} from '../../xhrInterceptor/responseModifiers/index.js'; |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 6 | |
avm99963 | b6f68b6 | 2021-08-12 23:13:06 +0200 | [diff] [blame] | 7 | import AutoRefresh from './autoRefresh.js'; |
Adrià Vilanova Martínez | 0d92a0c | 2023-11-06 01:37:20 +0100 | [diff] [blame] | 8 | import ExtraInfo from './extraInfo/index.js'; |
Adrià Vilanova Martínez | 72a4ea4 | 2024-02-09 22:35:32 +0100 | [diff] [blame] | 9 | import FlattenThreadsReplyActionHandler from './flattenThreads/replyActionHandler.js'; |
Adrià Vilanova Martínez | d2344c4 | 2022-09-30 13:14:29 +0200 | [diff] [blame] | 10 | import ThreadPageDesignWarning from './threadPageDesignWarning.js'; |
Adrià Vilanova Martínez | e0d65f2 | 2022-11-06 18:49:35 +0100 | [diff] [blame] | 11 | import WorkflowsImport from './workflows/import.js'; |
avm99963 | b6f68b6 | 2021-08-12 23:13:06 +0200 | [diff] [blame] | 12 | |
Adrià Vilanova Martínez | 849ede6 | 2022-06-20 19:10:28 +0200 | [diff] [blame] | 13 | const SMEI_NESTED_REPLIES = 15; |
| 14 | const SMEI_RCE_THREAD_INTEROP = 22; |
| 15 | |
Adrià Vilanova Martínez | 4b6ce46 | 2023-04-15 02:06:09 +0200 | [diff] [blame] | 16 | // The servers should be available as soon as possible, since e.g. the XHRProxy |
| 17 | // already sends a request to the optionsWatcher server as soon as it is |
| 18 | // constructed. |
| 19 | new MWOptionsWatcherServer(kCSTarget, kMWTarget); |
| 20 | new MWI18nServer(); |
| 21 | |
Adrià Vilanova Martínez | 102d54b | 2022-12-18 11:12:11 +0100 | [diff] [blame] | 22 | injectScript( |
| 23 | chrome.runtime.getURL('xhrInterceptorInject.bundle.js'), |
| 24 | /* prepend = */ true); |
Adrià Vilanova Martínez | 4e0cb18 | 2022-06-26 00:21:50 +0200 | [diff] [blame] | 25 | injectScript(chrome.runtime.getURL('extraInfoInject.bundle.js')); |
| 26 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 27 | getOptions(null).then(options => { |
Adrià Vilanova Martínez | d2ac4ce | 2021-06-11 16:41:43 +0200 | [diff] [blame] | 28 | /* IMPORTANT NOTE: Remember to change this when changing the "ifs" below!! */ |
Adrià Vilanova Martínez | 32fd642 | 2022-06-27 11:48:18 +0200 | [diff] [blame] | 29 | if (options.loaddrafts || options.interopthreadpage || |
| 30 | options.nestedreplies) { |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 31 | var startup = |
| 32 | JSON.parse(document.querySelector('html').getAttribute('data-startup')); |
avm99963 | c19497f | 2019-08-23 00:15:11 +0200 | [diff] [blame] | 33 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 34 | if (options.loaddrafts) { |
avm99963 | c19497f | 2019-08-23 00:15:11 +0200 | [diff] [blame] | 35 | startup[4][13] = true; |
| 36 | } |
| 37 | |
Adrià Vilanova Martínez | 849ede6 | 2022-06-20 19:10:28 +0200 | [diff] [blame] | 38 | if (options.interopthreadpage) { |
| 39 | var index = startup[1][6].indexOf(SMEI_RCE_THREAD_INTEROP); |
| 40 | |
| 41 | switch (options.interopthreadpage_mode) { |
| 42 | case 'previous': |
| 43 | if (index > -1) startup[1][6].splice(index, 1); |
| 44 | break; |
| 45 | |
| 46 | case 'next': |
| 47 | if (index == -1) startup[1][6].push(SMEI_RCE_THREAD_INTEROP); |
| 48 | break; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | if (options.nestedreplies) { |
| 53 | if (!startup[1][6].includes(SMEI_NESTED_REPLIES)) |
| 54 | startup[1][6].push(SMEI_NESTED_REPLIES); |
| 55 | } |
| 56 | |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 57 | document.querySelector('html').setAttribute( |
| 58 | 'data-startup', JSON.stringify(startup)); |
avm99963 | 6d9c5fe | 2019-06-04 00:35:53 +0200 | [diff] [blame] | 59 | } |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 60 | |
Adrià Vilanova Martínez | 7e8796c | 2022-01-23 21:46:46 +0100 | [diff] [blame] | 61 | // Initialized here instead of in main.js so the first event is received if it |
| 62 | // happens when the page loads. |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 63 | window.TWPTAutoRefresh = new AutoRefresh(); |
Adrià Vilanova Martínez | 7e8796c | 2022-01-23 21:46:46 +0100 | [diff] [blame] | 64 | window.TWPTExtraInfo = new ExtraInfo(); |
Adrià Vilanova Martínez | d2344c4 | 2022-09-30 13:14:29 +0200 | [diff] [blame] | 65 | window.TWPTThreadPageDesignWarning = new ThreadPageDesignWarning(); |
Adrià Vilanova Martínez | e0d65f2 | 2022-11-06 18:49:35 +0100 | [diff] [blame] | 66 | window.TWPTWorkflowsImport = new WorkflowsImport(); |
avm99963 | b6f68b6 | 2021-08-12 23:13:06 +0200 | [diff] [blame] | 67 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 68 | if (options.ccdarktheme) { |
| 69 | switch (options.ccdarktheme_mode) { |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 70 | case 'switch': |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 71 | if (options.ccdarktheme_switch_status == true) |
Adrià Vilanova Martínez | ddd3004 | 2023-11-01 22:54:17 +0100 | [diff] [blame] | 72 | injectStylesheet(chrome.runtime.getURL('ccDarkTheme.bundle.css')); |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 73 | break; |
| 74 | |
| 75 | case 'system': |
Adrià Vilanova Martínez | ddd3004 | 2023-11-01 22:54:17 +0100 | [diff] [blame] | 76 | injectStylesheet(chrome.runtime.getURL('ccDarkTheme.bundle.css'), { |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 77 | 'media': '(prefers-color-scheme: dark)', |
| 78 | }); |
| 79 | break; |
| 80 | } |
| 81 | } |
Adrià Vilanova Martínez | a2f7951 | 2022-07-10 15:32:32 +0200 | [diff] [blame] | 82 | |
| 83 | if (options.uispacing) { |
| 84 | injectStylesheet(chrome.runtime.getURL('css/ui_spacing/shared.css')); |
| 85 | injectStylesheet(chrome.runtime.getURL('css/ui_spacing/console.css')); |
| 86 | } |
Adrià Vilanova Martínez | 72a4ea4 | 2024-02-09 22:35:32 +0100 | [diff] [blame] | 87 | |
| 88 | const flattenThreadsReplyActionHandler = new FlattenThreadsReplyActionHandler(options); |
| 89 | flattenThreadsReplyActionHandler.handleIfApplicable(); |
avm99963 | 6d9c5fe | 2019-06-04 00:35:53 +0200 | [diff] [blame] | 90 | }); |