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