Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 1 | import {injectScript, injectStyles, injectStylesheet} from '../../common/contentScriptsUtils.js'; |
Adrià Vilanova Martínez | 4d59925 | 2023-02-04 20:54:54 +0100 | [diff] [blame] | 2 | import {getOptions} from '../../common/optionsUtils.js'; |
Adrià Vilanova Martínez | 825888a | 2023-07-23 01:53:48 +0200 | [diff] [blame] | 3 | import XHRProxyKillSwitchHandler from '../../xhrInterceptor/killSwitchHandler.js'; |
Adrià Vilanova Martínez | 1f65252 | 2021-10-14 00:23:23 +0200 | [diff] [blame] | 4 | import {injectPreviousPostsLinksUnifiedProfileIfEnabled} from '../utilsCommon/unifiedProfiles.js'; |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 5 | |
Adrià Vilanova Martínez | 27c6996 | 2021-07-17 23:32:51 +0200 | [diff] [blame] | 6 | import AvatarsHandler from './avatars.js'; |
Adrià Vilanova Martínez | 462280f | 2021-08-07 22:59:02 +0200 | [diff] [blame] | 7 | import {batchLock} from './batchLock.js'; |
Adrià Vilanova Martínez | 968e93c | 2024-03-11 23:18:16 +0100 | [diff] [blame] | 8 | import {injectDarkThemeButton, isDarkThemeOn} from './darkTheme/darkTheme.js'; |
Adrià Vilanova Martínez | f472d49 | 2024-03-05 21:26:53 +0100 | [diff] [blame] | 9 | import ReportDialogColorThemeFix from './darkTheme/reportDialog.js'; |
Adrià Vilanova Martínez | 968e93c | 2024-03-11 23:18:16 +0100 | [diff] [blame] | 10 | import {unifiedProfilesFix} from './darkTheme/unifiedProfiles.js'; |
Adrià Vilanova Martínez | eebc0ac | 2022-01-05 14:45:53 +0100 | [diff] [blame] | 11 | // #!if ['chromium', 'chromium_mv3'].includes(browser_target) |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 12 | import {applyDragAndDropFixIfEnabled} from './dragAndDropFix.js'; |
Adrià Vilanova Martínez | eebc0ac | 2022-01-05 14:45:53 +0100 | [diff] [blame] | 13 | // #!endif |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 14 | import {default as FlattenThreads, kMatchingSelectors as kFlattenThreadMatchingSelectors} from './flattenThreads/flattenThreads.js'; |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 15 | import {kRepliesSectionSelector} from './threadToolbar/constants.js'; |
| 16 | import ThreadToolbar from './threadToolbar/threadToolbar.js'; |
Adrià Vilanova Martínez | 2788d12 | 2022-10-10 22:06:25 +0200 | [diff] [blame] | 17 | import Workflows from './workflows/workflows.js'; |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 18 | |
Adrià Vilanova Martínez | 18d03c4 | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 19 | var mutationObserver, options, avatars, workflows, |
Adrià Vilanova Martínez | f472d49 | 2024-03-05 21:26:53 +0100 | [diff] [blame] | 20 | threadToolbar, flattenThreads, reportDialogColorThemeFix; |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 21 | |
| 22 | const watchedNodesSelectors = [ |
| 23 | // App container (used to set up the intersection observer and inject the dark |
| 24 | // mode button) |
| 25 | 'ec-app', |
| 26 | |
Adrià Vilanova Martínez | a7ae3db | 2022-01-28 11:57:27 +0100 | [diff] [blame] | 27 | // Scrollable content (used for the intersection observer) |
| 28 | '.scrollable-content', |
| 29 | |
| 30 | // Load more bar and buttons |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 31 | '.load-more-bar', |
Adrià Vilanova Martínez | a7ae3db | 2022-01-28 11:57:27 +0100 | [diff] [blame] | 32 | '.scTailwindThreadMorebuttonbutton', |
Adrià Vilanova Martínez | 8885497 | 2022-08-28 11:57:12 +0200 | [diff] [blame] | 33 | '.scTailwindThreadMessagegapbutton', |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 34 | |
Adrià Vilanova Martínez | 7e8796c | 2022-01-23 21:46:46 +0100 | [diff] [blame] | 35 | // User profile card inside ec-unified-user |
| 36 | 'ec-unified-user .scTailwindUser_profileUsercardmain', |
| 37 | |
Adrià Vilanova Martínez | 531cd07 | 2021-12-05 20:15:43 +0100 | [diff] [blame] | 38 | // Username span/editor inside ec-unified-user (user profile view) |
Adrià Vilanova Martínez | 1f65252 | 2021-10-14 00:23:23 +0200 | [diff] [blame] | 39 | 'ec-unified-user .scTailwindUser_profileUsercarddetails', |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 40 | |
| 41 | // Rich text editor |
| 42 | 'ec-movable-dialog', |
| 43 | 'ec-rich-text-editor', |
| 44 | |
| 45 | // Read/unread bulk action in the list of thread, for the batch lock feature |
| 46 | 'ec-bulk-actions material-button[debugid="mark-read-button"]', |
| 47 | 'ec-bulk-actions material-button[debugid="mark-unread-button"]', |
| 48 | |
Adrià Vilanova Martínez | 854cb91 | 2022-02-02 16:18:23 +0100 | [diff] [blame] | 49 | // Thread list items (used to inject the avatars and extra info) |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 50 | 'li', |
| 51 | |
Adrià Vilanova Martínez | 854cb91 | 2022-02-02 16:18:23 +0100 | [diff] [blame] | 52 | // Thread list item toolbelt (used for the extra info feature) |
| 53 | 'ec-thread-summary .main .toolbelt', |
| 54 | |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 55 | // Thread list (used for the autorefresh feature) |
| 56 | 'ec-thread-list', |
| 57 | |
Adrià Vilanova Martínez | f472d49 | 2024-03-05 21:26:53 +0100 | [diff] [blame] | 58 | // Unified profile iframe and report dialog iframe |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 59 | 'iframe', |
Adrià Vilanova Martínez | 74a2520 | 2022-01-23 23:36:58 +0100 | [diff] [blame] | 60 | |
Adrià Vilanova Martínez | 46ecb98 | 2024-01-30 22:02:17 +0100 | [diff] [blame] | 61 | // Canned response tags (for the "import CR" popup for the workflows feature) |
Adrià Vilanova Martínez | 6e4a68d | 2022-01-24 21:44:32 +0100 | [diff] [blame] | 62 | 'ec-canned-response-row .tags', |
Adrià Vilanova Martínez | 6e4a68d | 2022-01-24 21:44:32 +0100 | [diff] [blame] | 63 | |
Adrià Vilanova Martínez | 09b3bdb | 2022-02-05 00:15:05 +0100 | [diff] [blame] | 64 | // Question state chips container (for the extra info feature) |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 65 | 'sc-tailwind-thread-question-question-card sc-tailwind-thread-question-state-chips', |
Adrià Vilanova Martínez | 6e4a68d | 2022-01-24 21:44:32 +0100 | [diff] [blame] | 66 | |
| 67 | // Replies (for the extra info feature) |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 68 | 'sc-tailwind-thread-message-message-list sc-tailwind-thread-message-message-card', |
Adrià Vilanova Martínez | 4f56d56 | 2022-01-26 00:23:27 +0100 | [diff] [blame] | 69 | |
Adrià Vilanova Martínez | 80f1c73 | 2023-11-16 00:52:56 +0100 | [diff] [blame] | 70 | // Comments (for the extra info feature) |
| 71 | 'sc-tailwind-thread-message-message-list sc-tailwind-thread-message-comment-card', |
| 72 | |
Adrià Vilanova Martínez | 4f56d56 | 2022-01-26 00:23:27 +0100 | [diff] [blame] | 73 | // User activity chart (for the per-forum stats feature) |
| 74 | 'ec-unified-user .scTailwindUser_profileUserprofilesection ' + |
| 75 | 'sc-tailwind-shared-activity-chart', |
Adrià Vilanova Martínez | 5a8055b | 2022-09-29 13:05:19 +0200 | [diff] [blame] | 76 | |
| 77 | // Thread page main content |
| 78 | 'ec-thread > .page > .material-content > div[role="list"]', |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 79 | |
| 80 | // Thread page reply section (for the thread page toolbar) |
| 81 | kRepliesSectionSelector, |
Adrià Vilanova Martínez | 412b758 | 2022-12-30 01:35:30 +0100 | [diff] [blame] | 82 | |
| 83 | // Reply payload (for the flatten threads UI) |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 84 | ...kFlattenThreadMatchingSelectors, |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 85 | ]; |
| 86 | |
| 87 | function handleCandidateNode(node) { |
| 88 | if (typeof node.classList !== 'undefined') { |
| 89 | if (('tagName' in node) && node.tagName == 'EC-APP') { |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 90 | // Inject the dark mode button |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 91 | // TODO(avm99963): make this feature dynamic. |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 92 | if (options.ccdarktheme && options.ccdarktheme_mode == 'switch') { |
| 93 | var rightControl = node.querySelector('header .right-control'); |
| 94 | if (rightControl !== null) |
Adrià Vilanova Martínez | 968e93c | 2024-03-11 23:18:16 +0100 | [diff] [blame] | 95 | injectDarkThemeButton( |
| 96 | rightControl, options.ccdarktheme_switch_status); |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 97 | } |
| 98 | } |
| 99 | |
Adrià Vilanova Martínez | 7e8796c | 2022-01-23 21:46:46 +0100 | [diff] [blame] | 100 | // Show additional details in the profile view. |
| 101 | if (node.matches('ec-unified-user .scTailwindUser_profileUsercardmain')) { |
Adrià Vilanova Martínez | 0d92a0c | 2023-11-06 01:37:20 +0100 | [diff] [blame] | 102 | window.TWPTExtraInfo.injectAbuseChipsAtProfileIfEnabled(node); |
Adrià Vilanova Martínez | 7e8796c | 2022-01-23 21:46:46 +0100 | [diff] [blame] | 103 | } |
| 104 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 105 | // Show the "previous posts" links if the option is currently enabled. |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 106 | // Here we're selecting the 'ec-user > div' element (unique child) |
Adrià Vilanova Martínez | 1f65252 | 2021-10-14 00:23:23 +0200 | [diff] [blame] | 107 | if (node.matches( |
| 108 | 'ec-unified-user .scTailwindUser_profileUsercarddetails')) { |
| 109 | injectPreviousPostsLinksUnifiedProfileIfEnabled( |
| 110 | /* isCommunityConsole = */ true); |
| 111 | } |
| 112 | |
Adrià Vilanova Martínez | eebc0ac | 2022-01-05 14:45:53 +0100 | [diff] [blame] | 113 | // #!if ['chromium', 'chromium_mv3'].includes(browser_target) |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 114 | // Fix the drag&drop issue with the rich text editor if the option is |
| 115 | // currently enabled. |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 116 | // |
| 117 | // We target both tags because in different contexts different |
| 118 | // elements containing the text editor get added to the DOM structure. |
| 119 | // Sometimes it's a EC-MOVABLE-DIALOG which already contains the |
| 120 | // EC-RICH-TEXT-EDITOR, and sometimes it's the EC-RICH-TEXT-EDITOR |
| 121 | // directly. |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 122 | if (('tagName' in node) && |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 123 | (node.tagName == 'EC-MOVABLE-DIALOG' || |
| 124 | node.tagName == 'EC-RICH-TEXT-EDITOR')) { |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 125 | applyDragAndDropFixIfEnabled(node); |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 126 | } |
Adrià Vilanova Martínez | eebc0ac | 2022-01-05 14:45:53 +0100 | [diff] [blame] | 127 | // #!endif |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 128 | |
Adrià Vilanova Martínez | 2788d12 | 2022-10-10 22:06:25 +0200 | [diff] [blame] | 129 | // Inject the worflows menu in the thread list if the option is currently |
| 130 | // enabled. |
| 131 | if (workflows.shouldAddThreadListBtn(node)) { |
| 132 | workflows.addThreadListBtnIfEnabled(node); |
| 133 | } |
| 134 | |
Adrià Vilanova Martínez | b06c13d | 2022-06-20 17:30:14 +0000 | [diff] [blame] | 135 | // Inject the batch lock button in the thread list if the option is |
| 136 | // currently enabled. |
Adrià Vilanova Martínez | 4107b5e | 2022-10-09 23:11:11 +0200 | [diff] [blame] | 137 | if (batchLock.shouldAddButton(node)) { |
Adrià Vilanova Martínez | b06c13d | 2022-06-20 17:30:14 +0000 | [diff] [blame] | 138 | batchLock.addButtonIfEnabled(node); |
| 139 | } |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 140 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 141 | // Inject avatar links to threads in the thread list. injectIfEnabled is |
| 142 | // responsible of determining whether it should run or not depending on its |
| 143 | // current setting. |
Adrià Vilanova Martínez | 854cb91 | 2022-02-02 16:18:23 +0100 | [diff] [blame] | 144 | // |
| 145 | // Also, inject extra info in the thread list. |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 146 | if (('tagName' in node) && (node.tagName == 'LI') && |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 147 | node.querySelector('ec-thread-summary') !== null) { |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 148 | avatars.injectIfEnabled(node); |
Adrià Vilanova Martínez | 854cb91 | 2022-02-02 16:18:23 +0100 | [diff] [blame] | 149 | window.TWPTExtraInfo.injectAtThreadListIfEnabled(node); |
| 150 | } |
| 151 | |
| 152 | // Inject extra info in the toolbelt of an expanded thread list item. |
| 153 | if (node.matches('ec-thread-summary .main .toolbelt')) { |
| 154 | window.TWPTExtraInfo.injectAtExpandedThreadListIfEnabled(node); |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 155 | } |
| 156 | |
Adrià Vilanova Martínez | f472d49 | 2024-03-05 21:26:53 +0100 | [diff] [blame] | 157 | if (node.tagName == 'IFRAME') { |
| 158 | // Redirect unified profile iframe to dark version if applicable |
| 159 | if (isDarkThemeOn(options) && unifiedProfilesFix.checkIframe(node)) { |
| 160 | unifiedProfilesFix.fixIframe(node); |
| 161 | } |
| 162 | |
| 163 | // Set report dialog iframe's theme to the appropriate theme |
| 164 | reportDialogColorThemeFix.fixThemeIfReportDialogIframeAndApplicable(node); |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 165 | } |
Adrià Vilanova Martínez | 74a2520 | 2022-01-23 23:36:58 +0100 | [diff] [blame] | 166 | |
Adrià Vilanova Martínez | 46ecb98 | 2024-01-30 22:02:17 +0100 | [diff] [blame] | 167 | // Add the "import" button in the canned responses view for the workflows |
| 168 | // feature if applicable. |
Adrià Vilanova Martínez | 74a2520 | 2022-01-23 23:36:58 +0100 | [diff] [blame] | 169 | if (node.matches('ec-canned-response-row .tags')) { |
Adrià Vilanova Martínez | e0d65f2 | 2022-11-06 18:49:35 +0100 | [diff] [blame] | 170 | window.TWPTWorkflowsImport.addButtonIfEnabled(node); |
Adrià Vilanova Martínez | 74a2520 | 2022-01-23 23:36:58 +0100 | [diff] [blame] | 171 | } |
Adrià Vilanova Martínez | 6e4a68d | 2022-01-24 21:44:32 +0100 | [diff] [blame] | 172 | |
| 173 | // Show additional details in the thread view. |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 174 | if (node.matches( |
| 175 | 'sc-tailwind-thread-question-question-card sc-tailwind-thread-question-state-chips')) { |
Adrià Vilanova Martínez | 09b3bdb | 2022-02-05 00:15:05 +0100 | [diff] [blame] | 176 | window.TWPTExtraInfo.injectAtQuestionIfEnabled(node); |
Adrià Vilanova Martínez | 6e4a68d | 2022-01-24 21:44:32 +0100 | [diff] [blame] | 177 | } |
Adrià Vilanova Martínez | 19f6a65 | 2023-11-15 19:38:50 +0100 | [diff] [blame] | 178 | if (node.matches( |
| 179 | 'sc-tailwind-thread-message-message-list sc-tailwind-thread-message-message-card')) { |
Adrià Vilanova Martínez | 80f1c73 | 2023-11-16 00:52:56 +0100 | [diff] [blame] | 180 | window.TWPTExtraInfo.injectAtReplyIfEnabled(node); |
| 181 | } |
| 182 | |
| 183 | if (node.matches( |
| 184 | 'sc-tailwind-thread-message-message-list sc-tailwind-thread-message-comment-card')) { |
| 185 | window.TWPTExtraInfo.injectAtCommentIfEnabled(node); |
Adrià Vilanova Martínez | 74a2520 | 2022-01-23 23:36:58 +0100 | [diff] [blame] | 186 | } |
Adrià Vilanova Martínez | 4f56d56 | 2022-01-26 00:23:27 +0100 | [diff] [blame] | 187 | |
| 188 | // Inject per-forum stats section in the user profile |
| 189 | if (node.matches( |
| 190 | 'ec-unified-user .scTailwindUser_profileUserprofilesection ' + |
| 191 | 'sc-tailwind-shared-activity-chart')) { |
| 192 | window.TWPTExtraInfo.injectPerForumStatsIfEnabled(node); |
| 193 | } |
Adrià Vilanova Martínez | 5a8055b | 2022-09-29 13:05:19 +0200 | [diff] [blame] | 194 | |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 195 | // Inject old thread page design warning if applicable |
Adrià Vilanova Martínez | d2344c4 | 2022-09-30 13:14:29 +0200 | [diff] [blame] | 196 | if (node.matches( |
| 197 | 'ec-thread > .page > .material-content > div[role="list"]')) { |
| 198 | window.TWPTThreadPageDesignWarning.injectWarningIfApplicable(node); |
Adrià Vilanova Martínez | 5a8055b | 2022-09-29 13:05:19 +0200 | [diff] [blame] | 199 | } |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 200 | |
| 201 | // Inject thread toolbar |
| 202 | if (threadToolbar.shouldInject(node)) { |
| 203 | threadToolbar.injectIfApplicable(node); |
| 204 | } |
Adrià Vilanova Martínez | 412b758 | 2022-12-30 01:35:30 +0100 | [diff] [blame] | 205 | |
| 206 | // Inject parent reply quote |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 207 | if (flattenThreads.shouldInjectQuote(node)) { |
| 208 | flattenThreads.injectQuoteIfApplicable(node); |
| 209 | } |
| 210 | |
| 211 | // Inject reply button in non-nested view |
| 212 | if (flattenThreads.shouldInjectReplyBtn(node)) { |
| 213 | flattenThreads.injectReplyBtnIfApplicable(node); |
Adrià Vilanova Martínez | 412b758 | 2022-12-30 01:35:30 +0100 | [diff] [blame] | 214 | } |
Adrià Vilanova Martínez | 4d59925 | 2023-02-04 20:54:54 +0100 | [diff] [blame] | 215 | |
| 216 | // Delete additional info in the edit message box |
| 217 | if (flattenThreads.isAdditionalInfoElement(node)) { |
| 218 | flattenThreads.deleteAdditionalInfoElementIfApplicable(node); |
| 219 | } |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 220 | } |
| 221 | } |
| 222 | |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 223 | function handleRemovedNode(mutation, node) { |
| 224 | if (!('tagName' in node)) return; |
| 225 | |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 226 | // Readd reply button when the Community Console removes it |
| 227 | if (node.tagName == 'TWPT-FLATTEN-THREAD-REPLY-BUTTON') { |
| 228 | flattenThreads.injectReplyBtn( |
| 229 | mutation.target, JSON.parse(node.getAttribute('extraInfo'))); |
| 230 | } |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 231 | } |
| 232 | |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 233 | function mutationCallback(mutationList) { |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 234 | mutationList.forEach((mutation) => { |
| 235 | if (mutation.type == 'childList') { |
| 236 | mutation.addedNodes.forEach(function(node) { |
| 237 | handleCandidateNode(node); |
| 238 | }); |
| 239 | |
| 240 | mutation.removedNodes.forEach(function(node) { |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 241 | handleRemovedNode(mutation, node); |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 242 | }); |
| 243 | } |
| 244 | }); |
| 245 | } |
| 246 | |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 247 | var observerOptions = { |
| 248 | childList: true, |
| 249 | subtree: true, |
| 250 | }; |
| 251 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 252 | getOptions(null).then(items => { |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 253 | options = items; |
| 254 | |
Adrià Vilanova Martínez | 27c6996 | 2021-07-17 23:32:51 +0200 | [diff] [blame] | 255 | // Initialize classes needed by the mutation observer |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 256 | avatars = new AvatarsHandler(); |
Adrià Vilanova Martínez | 2788d12 | 2022-10-10 22:06:25 +0200 | [diff] [blame] | 257 | workflows = new Workflows(); |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 258 | threadToolbar = new ThreadToolbar(); |
Adrià Vilanova Martínez | 412b758 | 2022-12-30 01:35:30 +0100 | [diff] [blame] | 259 | flattenThreads = new FlattenThreads(); |
Adrià Vilanova Martínez | f472d49 | 2024-03-05 21:26:53 +0100 | [diff] [blame] | 260 | reportDialogColorThemeFix = new ReportDialogColorThemeFix(options); |
Adrià Vilanova Martínez | 27c6996 | 2021-07-17 23:32:51 +0200 | [diff] [blame] | 261 | |
Adrià Vilanova Martínez | 58cc67c | 2024-04-21 16:43:01 +0200 | [diff] [blame] | 262 | // extraInfo, threadPageDesignWarning and workflowsImport are |
Adrià Vilanova Martínez | e0d65f2 | 2022-11-06 18:49:35 +0100 | [diff] [blame] | 263 | // initialized in start.js |
avm99963 | d3f4ac0 | 2021-08-12 18:36:58 +0200 | [diff] [blame] | 264 | |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 265 | // Before starting the mutation Observer, check whether we missed any |
| 266 | // mutations by manually checking whether some watched nodes already |
| 267 | // exist. |
| 268 | var cssSelectors = watchedNodesSelectors.join(','); |
| 269 | document.querySelectorAll(cssSelectors) |
| 270 | .forEach(node => handleCandidateNode(node)); |
| 271 | |
| 272 | mutationObserver = new MutationObserver(mutationCallback); |
| 273 | mutationObserver.observe(document.body, observerOptions); |
| 274 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 275 | // TODO(avm99963): The following features are not dynamic. Make them be. |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 276 | if (options.fixedtoolbar) { |
| 277 | injectStyles( |
Adrià Vilanova | e8ba09a | 2024-02-29 19:25:39 +0000 | [diff] [blame] | 278 | 'ec-bulk-actions{position: sticky; top: 0; background: var(--TWPT-primary-background, #fff); z-index: 96;}'); |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 279 | } |
| 280 | |
| 281 | if (options.increasecontrast) { |
| 282 | injectStyles( |
| 283 | '.thread-summary.read:not(.checked){background: var(--TWPT-thread-read-background, #ecedee)!important;}'); |
| 284 | } |
| 285 | |
| 286 | if (options.stickysidebarheaders) { |
| 287 | injectStyles( |
| 288 | 'material-drawer .main-header{background: var(--TWPT-drawer-background, #fff)!important; position: sticky; top: 0; z-index: 1;}'); |
| 289 | } |
| 290 | |
| 291 | if (options.enhancedannouncementsdot) { |
| 292 | injectStylesheet( |
| 293 | chrome.runtime.getURL('css/enhanced_announcements_dot.css')); |
| 294 | } |
| 295 | |
| 296 | if (options.repositionexpandthread) { |
Adrià Vilanova Martínez | 27c6996 | 2021-07-17 23:32:51 +0200 | [diff] [blame] | 297 | injectStylesheet(chrome.runtime.getURL('css/reposition_expand_thread.css')); |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 298 | } |
| 299 | |
Adrià Vilanova Martínez | 9d27c21 | 2021-12-05 13:54:10 +0100 | [diff] [blame] | 300 | if (options.imagemaxheight) { |
| 301 | injectStylesheet(chrome.runtime.getURL('css/image_max_height.css')); |
| 302 | } |
| 303 | |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 304 | if (options.ccforcehidedrawer) { |
| 305 | var drawer = document.querySelector('material-drawer'); |
| 306 | if (drawer !== null && drawer.classList.contains('mat-drawer-expanded')) { |
| 307 | document.querySelector('.material-drawer-button').click(); |
| 308 | } |
| 309 | } |
| 310 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 311 | // Batch lock |
| 312 | injectScript(chrome.runtime.getURL('batchLockInject.bundle.js')); |
| 313 | injectStylesheet(chrome.runtime.getURL('css/batchlock_inject.css')); |
| 314 | // Thread list avatars |
| 315 | injectStylesheet(chrome.runtime.getURL('css/thread_list_avatars.css')); |
Adrià Vilanova Martínez | 7e8796c | 2022-01-23 21:46:46 +0100 | [diff] [blame] | 316 | // Extra info |
| 317 | injectStylesheet(chrome.runtime.getURL('css/extrainfo.css')); |
avm99963 | 37601bc | 2022-02-21 10:36:45 +0100 | [diff] [blame] | 318 | injectStylesheet(chrome.runtime.getURL('css/extrainfo_perforumstats.css')); |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 319 | // Workflows, Thread toolbar |
| 320 | injectScript(chrome.runtime.getURL('litComponentsInject.bundle.js')); |
| 321 | // Thread toolbar |
| 322 | injectStylesheet(chrome.runtime.getURL('css/thread_toolbar.css')); |
Adrià Vilanova Martínez | 115e3d8 | 2023-01-10 21:50:06 +0100 | [diff] [blame] | 323 | // Flatten threads |
| 324 | injectStylesheet(chrome.runtime.getURL('css/flatten_threads.css')); |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 325 | }); |
Adrià Vilanova Martínez | 825888a | 2023-07-23 01:53:48 +0200 | [diff] [blame] | 326 | |
| 327 | new XHRProxyKillSwitchHandler(); |