(button: HTMLButtonElement)
| 23 | }; |
| 24 | |
| 25 | function getParticipants(button: HTMLButtonElement): Participant[] { |
| 26 | let users; |
| 27 | |
| 28 | if (button.getAttribute('role') === 'switch') { // [aria-label] alone is not a differentiator |
| 29 | users = button.nextElementSibling! |
| 30 | .textContent |
| 31 | .replace(/^.+including /, '') |
| 32 | .replace(/\)/, '') |
| 33 | .replace(/,? and /, ', ') |
| 34 | .replace(/, \d+ more/, '') |
| 35 | .split(', '); |
| 36 | // Uses optional chaining to throw an error manually later |
| 37 | } else if (button.nextElementSibling?.tagName === 'TOOL-TIP') { |
| 38 | // The list of people who commented is in an adjacent `<tool-tip>` element #5698 |
| 39 | users = button.nextElementSibling |
| 40 | .textContent |
| 41 | .replace(/ reacted with.*/, '') |
| 42 | .replace(/,? and /, ', ') |
| 43 | .replace(/, \d+ more/, '') |
| 44 | .split(', '); |
| 45 | } else { |
| 46 | throw new Error('Unknown reaction button layout'); |
| 47 | } |
| 48 | |
| 49 | const currentUser = getLoggedInUser(); |
| 50 | const participants = []; |
| 51 | for (const username of users) { |
| 52 | if (username === currentUser) { |
| 53 | continue; |
| 54 | } |
| 55 | |
| 56 | const imageUrl = getUserAvatar(username, avatarSize); |
| 57 | if (imageUrl) { |
| 58 | participants.push({button, username, imageUrl}); |
| 59 | } |
| 60 | } |
| 61 | |
| 62 | return participants; |
| 63 | } |
| 64 | |
| 65 | function showAvatarsOn(reactionsContainer: Element): void { |
| 66 | const reactions = $$optional([ |
no test coverage detected