(found: HTMLAnchorElement[])
| 69 | } |
| 70 | |
| 71 | async function updateLinks(found: HTMLAnchorElement[]): Promise<void> { |
| 72 | const users = Map.groupBy( |
| 73 | // Exclude nested items https://github.com/refined-github/refined-github/pull/8661 |
| 74 | found.filter(element => element.textContent.trim() === element.href.split('/').pop()), |
| 75 | element => element.textContent.trim(), |
| 76 | ); |
| 77 | const currentUser = getLoggedInUser()!; |
| 78 | const currentUserElements = users.get(currentUser); |
| 79 | if (currentUserElements) { |
| 80 | for (const currentUserElement of currentUserElements) { |
| 81 | // For `sticky-comment-header`. Use attribute because classes are altered by GitHub |
| 82 | closestElementOptional('[data-testid="comment-header"]', currentUserElement)?.setAttribute( |
| 83 | 'data-rgh-viewer-did-author', |
| 84 | '', |
| 85 | ); |
| 86 | } |
| 87 | |
| 88 | users.delete(currentUser); |
| 89 | } |
| 90 | |
| 91 | users.delete('ghost'); // Consider using `github-reserved-names` if more exclusions are needed |
| 92 | |
| 93 | if (users.size === 0) { |
| 94 | return; |
| 95 | } |
| 96 | |
| 97 | const names = await api.v4( |
| 98 | [...users.keys()].map(username => api.escapeKey(username) + `: user(login: "${username}") { name }`).join(','), |
| 99 | ); |
| 100 | |
| 101 | for (const [username, elements] of users) { |
| 102 | const userKey = api.escapeKey(username); |
| 103 | const {name: fullName} = names[userKey]; |
| 104 | |
| 105 | // Could be `null` if not set or empty string if consisting only of emojis |
| 106 | const fullNameWithoutEmoji = fullName?.replaceAll(/\p{RGI_Emoji}/gv, '').trim(); |
| 107 | if (!fullNameWithoutEmoji) { |
| 108 | continue; |
| 109 | } |
| 110 | |
| 111 | for (const element of elements) { |
| 112 | if (isUsernameAlreadyFullName(username, fullNameWithoutEmoji)) { |
| 113 | element.textContent = fullNameWithoutEmoji; |
| 114 | } else { |
| 115 | appendName(element, fullNameWithoutEmoji); |
| 116 | } |
| 117 | } |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | const updateLink = batchedFunction(updateLinks, {delay: 200}); |
| 122 |
nothing calls this directly
no test coverage detected