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 | 412b758 | 2022-12-30 01:35:30 +0100 | [diff] [blame^] | 11 | import {default as FlattenThreads, kReplyPayloadSelector} 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) |
| 82 | kReplyPayloadSelector, |
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 |
| 223 | if (flattenThreads.shouldInject(node)) { |
| 224 | flattenThreads.injectIfApplicable(node); |
| 225 | } |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | |
| 229 | function handleRemovedNode(node) { |
| 230 | // Remove snackbar when exiting thread list view |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 231 | if ('tagName' in node && node.tagName == 'EC-THREAD-LIST') { |
avm99963 | fd22267 | 2021-08-12 23:23:01 +0200 | [diff] [blame] | 232 | window.TWPTAutoRefresh.hideUpdatePrompt(); |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 233 | } |
| 234 | } |
| 235 | |
| 236 | function mutationCallback(mutationList, observer) { |
| 237 | mutationList.forEach((mutation) => { |
| 238 | if (mutation.type == 'childList') { |
| 239 | mutation.addedNodes.forEach(function(node) { |
| 240 | handleCandidateNode(node); |
| 241 | }); |
| 242 | |
| 243 | mutation.removedNodes.forEach(function(node) { |
| 244 | handleRemovedNode(node); |
| 245 | }); |
| 246 | } |
| 247 | }); |
| 248 | } |
| 249 | |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 250 | var observerOptions = { |
| 251 | childList: true, |
| 252 | subtree: true, |
| 253 | }; |
| 254 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 255 | getOptions(null).then(items => { |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 256 | options = items; |
| 257 | |
Adrià Vilanova Martínez | 27c6996 | 2021-07-17 23:32:51 +0200 | [diff] [blame] | 258 | // Initialize classes needed by the mutation observer |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 259 | avatars = new AvatarsHandler(); |
Adrià Vilanova Martínez | a7ae3db | 2022-01-28 11:57:27 +0100 | [diff] [blame] | 260 | infiniteScroll = new InfiniteScroll(); |
Adrià Vilanova Martínez | 2788d12 | 2022-10-10 22:06:25 +0200 | [diff] [blame] | 261 | workflows = new Workflows(); |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 262 | threadToolbar = new ThreadToolbar(); |
Adrià Vilanova Martínez | 412b758 | 2022-12-30 01:35:30 +0100 | [diff] [blame^] | 263 | flattenThreads = new FlattenThreads(); |
Adrià Vilanova Martínez | 27c6996 | 2021-07-17 23:32:51 +0200 | [diff] [blame] | 264 | |
Adrià Vilanova Martínez | e0d65f2 | 2022-11-06 18:49:35 +0100 | [diff] [blame] | 265 | // autoRefresh, extraInfo, threadPageDesignWarning and workflowsImport are |
| 266 | // initialized in start.js |
avm99963 | d3f4ac0 | 2021-08-12 18:36:58 +0200 | [diff] [blame] | 267 | |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 268 | // Before starting the mutation Observer, check whether we missed any |
| 269 | // mutations by manually checking whether some watched nodes already |
| 270 | // exist. |
| 271 | var cssSelectors = watchedNodesSelectors.join(','); |
| 272 | document.querySelectorAll(cssSelectors) |
| 273 | .forEach(node => handleCandidateNode(node)); |
| 274 | |
| 275 | mutationObserver = new MutationObserver(mutationCallback); |
| 276 | mutationObserver.observe(document.body, observerOptions); |
| 277 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 278 | // 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] | 279 | if (options.fixedtoolbar) { |
| 280 | injectStyles( |
| 281 | 'ec-bulk-actions{position: sticky; top: 0; background: var(--TWPT-primary-background, #fff); z-index: 96;}'); |
| 282 | } |
| 283 | |
| 284 | if (options.increasecontrast) { |
| 285 | injectStyles( |
| 286 | '.thread-summary.read:not(.checked){background: var(--TWPT-thread-read-background, #ecedee)!important;}'); |
| 287 | } |
| 288 | |
| 289 | if (options.stickysidebarheaders) { |
| 290 | injectStyles( |
| 291 | 'material-drawer .main-header{background: var(--TWPT-drawer-background, #fff)!important; position: sticky; top: 0; z-index: 1;}'); |
| 292 | } |
| 293 | |
| 294 | if (options.enhancedannouncementsdot) { |
| 295 | injectStylesheet( |
| 296 | chrome.runtime.getURL('css/enhanced_announcements_dot.css')); |
| 297 | } |
| 298 | |
| 299 | if (options.repositionexpandthread) { |
Adrià Vilanova Martínez | 27c6996 | 2021-07-17 23:32:51 +0200 | [diff] [blame] | 300 | injectStylesheet(chrome.runtime.getURL('css/reposition_expand_thread.css')); |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 301 | } |
| 302 | |
Adrià Vilanova Martínez | 9d27c21 | 2021-12-05 13:54:10 +0100 | [diff] [blame] | 303 | if (options.imagemaxheight) { |
| 304 | injectStylesheet(chrome.runtime.getURL('css/image_max_height.css')); |
| 305 | } |
| 306 | |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 307 | if (options.ccforcehidedrawer) { |
| 308 | var drawer = document.querySelector('material-drawer'); |
| 309 | if (drawer !== null && drawer.classList.contains('mat-drawer-expanded')) { |
| 310 | document.querySelector('.material-drawer-button').click(); |
| 311 | } |
| 312 | } |
| 313 | |
Adrià Vilanova Martínez | d269c62 | 2021-09-04 18:35:55 +0200 | [diff] [blame] | 314 | // Batch lock |
| 315 | injectScript(chrome.runtime.getURL('batchLockInject.bundle.js')); |
| 316 | injectStylesheet(chrome.runtime.getURL('css/batchlock_inject.css')); |
| 317 | // Thread list avatars |
| 318 | injectStylesheet(chrome.runtime.getURL('css/thread_list_avatars.css')); |
| 319 | // Auto refresh list |
| 320 | injectStylesheet(chrome.runtime.getURL('css/autorefresh_list.css')); |
Adrià Vilanova Martínez | 7e8796c | 2022-01-23 21:46:46 +0100 | [diff] [blame] | 321 | // Extra info |
| 322 | injectStylesheet(chrome.runtime.getURL('css/extrainfo.css')); |
avm99963 | 37601bc | 2022-02-21 10:36:45 +0100 | [diff] [blame] | 323 | injectStylesheet(chrome.runtime.getURL('css/extrainfo_perforumstats.css')); |
Adrià Vilanova Martínez | 2d9be8d | 2022-12-28 00:50:14 +0100 | [diff] [blame] | 324 | // Workflows, Thread toolbar |
| 325 | injectScript(chrome.runtime.getURL('litComponentsInject.bundle.js')); |
| 326 | // Thread toolbar |
| 327 | injectStylesheet(chrome.runtime.getURL('css/thread_toolbar.css')); |
Adrià Vilanova Martínez | 3465e77 | 2021-07-11 19:18:41 +0200 | [diff] [blame] | 328 | }); |