Show lastlogoff as relative last-seen time, label friend_since as 'friends since YYYY', and show the Steam account creation year in the comparison header.
This commit is contained in:
1 parent
80aae1a1df
commit
85ff1e3893
7 files changed
+55
-7
No files matched your search
+28
-3
@@ -1402,12 +1402,35 @@ function friendOnline(friend) {
|
||||
function friendSince(friend) {
|
||||
if (!friend.friend_since) return "";
|
||||
const date = new Date(friend.friend_since * 1000);
|
||||
return Number.isNaN(date.getTime()) ? "" : `с ${date.getFullYear()}`;
|
||||
return Number.isNaN(date.getTime()) ? "" : `в друзьях с ${date.getFullYear()}`;
|
||||
}
|
||||
|
||||
function relativeTime(timestamp) {
|
||||
if (!timestamp) return "";
|
||||
const seconds = Math.max(0, Math.floor(Date.now() / 1000 - timestamp));
|
||||
if (seconds < 60) return "только что";
|
||||
const minutes = Math.floor(seconds / 60);
|
||||
if (minutes < 60) return `${minutes} мин назад`;
|
||||
const hours = Math.floor(minutes / 60);
|
||||
if (hours < 24) return `${hours} ч назад`;
|
||||
const days = Math.floor(hours / 24);
|
||||
if (days < 30) return `${days} дн назад`;
|
||||
return new Date(timestamp * 1000).toLocaleDateString("ru-RU");
|
||||
}
|
||||
|
||||
function friendLastSeen(friend) {
|
||||
if (friendOnline(friend)) return FRIEND_STATE[Number(friend.state)] || "в сети";
|
||||
if (friend.lastlogoff) return `был(а) в сети ${relativeTime(friend.lastlogoff)}`;
|
||||
return "офлайн";
|
||||
}
|
||||
|
||||
function friendAccountAge(friend) {
|
||||
if (!friend.created) return "";
|
||||
return `в Steam с ${new Date(friend.created * 1000).getFullYear()}`;
|
||||
}
|
||||
|
||||
function friendCardHtml(friend) {
|
||||
const online = friendOnline(friend);
|
||||
const label = FRIEND_STATE[Number(friend.state)] || "";
|
||||
const since = friendSince(friend);
|
||||
return `<button class="friend-card" type="button" data-steamid="${esc(friend.steamid)}">
|
||||
<span class="friend-avatar-wrap">
|
||||
@@ -1418,7 +1441,8 @@ function friendCardHtml(friend) {
|
||||
</span>
|
||||
<span class="friend-info">
|
||||
<b>${esc(friend.name)}</b>
|
||||
<span class="friend-meta">${esc(label)}${since ? ` · ${esc(since)}` : ""}</span>
|
||||
<span class="friend-meta">${esc(friendLastSeen(friend))}</span>
|
||||
${since ? `<span class="friend-since">${esc(since)}</span>` : ""}
|
||||
</span>
|
||||
</button>`;
|
||||
}
|
||||
@@ -1497,6 +1521,7 @@ function renderFriendCompare(data) {
|
||||
<div class="friend-title">
|
||||
<h2>${esc(data.name)}</h2>
|
||||
<div class="muted">общих: ${data.common_count} · всего у друга: ${data.total_games} · вне библиотеки: ${data.friend_only_count}</div>
|
||||
<div class="muted">${esc(friendLastSeen(data))}${friendAccountAge(data) ? ` · ${esc(friendAccountAge(data))}` : ""}</div>
|
||||
<a class="friend-profile" href="${esc(data.profile_url)}" target="_blank" rel="noopener">профиль Steam ↗</a>
|
||||
</div>
|
||||
<button id="friendClose" class="link" type="button">закрыть</button>
|
||||
|
||||
Reference in new issue
Block a user