MCPcopy
hub / github.com/refined-github/refined-github / getUserAvatar

Function getUserAvatar

source/github-helpers/get-user-avatar.ts:4–36  ·  view source on GitHub ↗
(username: string, size: number)

Source from the content-addressed store, hash-verified

2import {$optional} from 'select-dom';
3
4export default function getUserAvatar(username: string, size: number): string | void {
5 let cleanName = username.replace('[bot]', '');
6
7 if (/[^\w-]/.test(cleanName)) {
8 throw new TypeError(`Expected a username, got ${cleanName}`);
9 }
10
11 // Find image on page. Saves a request and a redirect + add support for bots
12 const existingAvatar = $optional(`[href="/${cleanName}" i] img`);
13 if (existingAvatar) {
14 return existingAvatar.src;
15 }
16
17 if (
18 [
19 'Copilot',
20 'copilot-coding-agent-docs',
21 'copilot-swe-agent',
22 ].includes(cleanName)
23 ) {
24 cleanName = 'in/1143301';
25 }
26
27 // Bots don't have a /$username.png URL
28 // Enterprise can only use /$username.png
29 const isBot = username.endsWith('[bot]') || cleanName.includes('/');
30 const url = pageDetect.isEnterprise() || !isBot
31 // Use full URLs: https://github.com/refined-github/refined-github/issues/9571
32 ? `${location.origin}/${cleanName}.png`
33 : `https://avatars.githubusercontent.com/${cleanName}`;
34 // Why use a 2x size: https://github.com/refined-github/refined-github/pull/4973#discussion_r735133613
35 return url + `?size=${size * 2}`;
36}

Callers 2

getParticipantsFunction · 0.85
addFunction · 0.85

Calls 2

replaceMethod · 0.80
includesMethod · 0.80

Tested by

no test coverage detected