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 | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 2 | import {getOptions} from '../../common/optionsUtils.js'; |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 3 | |
avm99963 | b6f68b6 | 2021-08-12 23:13:06 +0200 | [diff] [blame] | 4 | import AutoRefresh from './autoRefresh.js'; |
Adrià Vilanova Martínez | 7e8796c | 2022-01-23 21:46:46 +0100 | [diff] [blame] | 5 | import ExtraInfo from './extraInfo.js'; |
Adrià Vilanova Martínez | d2344c4 | 2022-09-30 13:14:29 +0200 | [diff] [blame] | 6 | import ThreadPageDesignWarning from './threadPageDesignWarning.js'; |
avm99963 | b6f68b6 | 2021-08-12 23:13:06 +0200 | [diff] [blame] | 7 | |
Adrià Vilanova Martínez | 849ede6 | 2022-06-20 19:10:28 +0200 | [diff] [blame] | 8 | const SMEI_NESTED_REPLIES = 15; |
| 9 | const SMEI_RCE_THREAD_INTEROP = 22; |
| 10 | |
Adrià Vilanova Martínez | 4e0cb18 | 2022-06-26 00:21:50 +0200 | [diff] [blame] | 11 | injectScript(chrome.runtime.getURL('xhrInterceptorInject.bundle.js')); |
| 12 | injectScript(chrome.runtime.getURL('extraInfoInject.bundle.js')); |
| 13 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 14 | getOptions(null).then(options => { |
Adrià Vilanova Martínez | d2ac4ce | 2021-06-11 16:41:43 +0200 | [diff] [blame] | 15 | /* 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] | 16 | if (options.loaddrafts || options.interopthreadpage || |
| 17 | options.nestedreplies) { |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 18 | var startup = |
| 19 | JSON.parse(document.querySelector('html').getAttribute('data-startup')); |
avm99963 | c19497f | 2019-08-23 00:15:11 +0200 | [diff] [blame] | 20 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 21 | if (options.loaddrafts) { |
avm99963 | c19497f | 2019-08-23 00:15:11 +0200 | [diff] [blame] | 22 | startup[4][13] = true; |
| 23 | } |
| 24 | |
Adrià Vilanova Martínez | 849ede6 | 2022-06-20 19:10:28 +0200 | [diff] [blame] | 25 | if (options.interopthreadpage) { |
| 26 | var index = startup[1][6].indexOf(SMEI_RCE_THREAD_INTEROP); |
| 27 | |
| 28 | switch (options.interopthreadpage_mode) { |
| 29 | case 'previous': |
| 30 | if (index > -1) startup[1][6].splice(index, 1); |
| 31 | break; |
| 32 | |
| 33 | case 'next': |
| 34 | if (index == -1) startup[1][6].push(SMEI_RCE_THREAD_INTEROP); |
| 35 | break; |
| 36 | } |
| 37 | } |
| 38 | |
| 39 | if (options.nestedreplies) { |
| 40 | if (!startup[1][6].includes(SMEI_NESTED_REPLIES)) |
| 41 | startup[1][6].push(SMEI_NESTED_REPLIES); |
| 42 | } |
| 43 | |
avm99963 | b69eb3d | 2020-08-20 02:03:44 +0200 | [diff] [blame] | 44 | document.querySelector('html').setAttribute( |
| 45 | 'data-startup', JSON.stringify(startup)); |
avm99963 | 6d9c5fe | 2019-06-04 00:35:53 +0200 | [diff] [blame] | 46 | } |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 47 | |
Adrià Vilanova Martínez | 7e8796c | 2022-01-23 21:46:46 +0100 | [diff] [blame] | 48 | // Initialized here instead of in main.js so the first event is received if it |
| 49 | // happens when the page loads. |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 50 | window.TWPTAutoRefresh = new AutoRefresh(); |
Adrià Vilanova Martínez | 7e8796c | 2022-01-23 21:46:46 +0100 | [diff] [blame] | 51 | window.TWPTExtraInfo = new ExtraInfo(); |
Adrià Vilanova Martínez | d2344c4 | 2022-09-30 13:14:29 +0200 | [diff] [blame] | 52 | window.TWPTThreadPageDesignWarning = new ThreadPageDesignWarning(); |
avm99963 | b6f68b6 | 2021-08-12 23:13:06 +0200 | [diff] [blame] | 53 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 54 | if (options.ccdarktheme) { |
| 55 | switch (options.ccdarktheme_mode) { |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 56 | case 'switch': |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 57 | if (options.ccdarktheme_switch_status == true) |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 58 | injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css')); |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 59 | break; |
| 60 | |
| 61 | case 'system': |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 62 | injectStylesheet(chrome.runtime.getURL('css/ccdarktheme.css'), { |
avm99963 | 0bc113a | 2020-09-07 13:02:11 +0200 | [diff] [blame] | 63 | 'media': '(prefers-color-scheme: dark)', |
| 64 | }); |
| 65 | break; |
| 66 | } |
| 67 | } |
Adrià Vilanova Martínez | a2f7951 | 2022-07-10 15:32:32 +0200 | [diff] [blame] | 68 | |
| 69 | if (options.uispacing) { |
| 70 | injectStylesheet(chrome.runtime.getURL('css/ui_spacing/shared.css')); |
| 71 | injectStylesheet(chrome.runtime.getURL('css/ui_spacing/console.css')); |
| 72 | } |
avm99963 | 6d9c5fe | 2019-06-04 00:35:53 +0200 | [diff] [blame] | 73 | }); |