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