Skip to content

Commit

Permalink
Added support for animated avatars.
Browse files Browse the repository at this point in the history
  • Loading branch information
Bilge committed Feb 1, 2025
1 parent 8470e0c commit c598f3a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 6 additions & 1 deletion assets/css/250.less
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,19 @@ h2 {

#user .avatar {
display: inline-block;
overflow: hidden;
width: 32px;
height: $width;
padding: 1px;
margin: 0 .5em;
line-height: 0;
vertical-align: middle;

background: #3f7085;
border: 1px solid #4c92ae;

>img {
width: 100%;
}
}
#user button {
margin: 0 .5em;
Expand Down
14 changes: 10 additions & 4 deletions assets/js/User.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,12 @@ export default class User {
}

const [userId, identity, noads, tier] = body.split("\0", 4);
let avatar = identity.match(/^(?:\d+\/[\da-z]{40}\..{3}|[\da-z]{40})/)?.[0];

localStorage.setItem('user', JSON.stringify({
id: userId,
name: identity.substring(40),
avatar: identity.substring(0, 40),
avatar,
name: avatar ? identity.substring(avatar.length) : 'ERROR',
noads: noads === '1',
tier: +tier,
}));
Expand Down Expand Up @@ -116,6 +117,8 @@ export default class User {
}

private static updateUserBar() {
const IMAGE_BASE_URL = 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images';

const userJson = localStorage.getItem('user');
if (!userJson) return;

Expand All @@ -127,8 +130,11 @@ export default class User {

const img = a.appendChild(document.createElement('img'));
img.alt = img.title = user.name;
img.src = 'https://cdn.cloudflare.steamstatic.com/steamcommunity/public/images/avatars/'
+ `${user.avatar.substring(0, 2)}/${user.avatar}.jpg'`;
if (user.avatar.includes('/')) {
img.src = `${IMAGE_BASE_URL}/items/${user.avatar}`;
} else {
img.src = `${IMAGE_BASE_URL}/avatars/${user.avatar.substring(0, 2)}/${user.avatar}.jpg'`;
}

this.markOwnedGames();
}
Expand Down

0 comments on commit c598f3a

Please sign in to comment.