Stats: tidy leaderboards (even rows, aligned values and level pills, wider Points board)

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Bashy 2026-11-22 17:53:18 +02:00
parent dd0e92c0bb
commit 024934f09f

View file

@ -14,14 +14,24 @@
.chart .ax { fill:var(--pico-muted-color); font-size:10px; } .chart .ax { fill:var(--pico-muted-color); font-size:10px; }
.tip { position:absolute; pointer-events:none; background:var(--pico-card-background-color); border:1px solid var(--pico-muted-border-color); .tip { position:absolute; pointer-events:none; background:var(--pico-card-background-color); border:1px solid var(--pico-muted-border-color);
border-radius:8px; padding:.25rem .5rem; font-size:.8rem; box-shadow:0 4px 12px rgba(0,0,0,.35); white-space:nowrap; display:none; z-index:5; } border-radius:8px; padding:.25rem .5rem; font-size:.8rem; box-shadow:0 4px 12px rgba(0,0,0,.35); white-space:nowrap; display:none; z-index:5; }
.boards { display:grid; grid-template-columns:repeat(auto-fit, minmax(260px, 1fr)); gap:1rem; } .boards { display:grid; grid-template-columns:repeat(auto-fill, minmax(320px, 1fr)); gap:1rem; }
.board { border:1px solid var(--pico-muted-border-color); border-radius:12px; padding:.6rem .8rem; } .board { border:1px solid var(--pico-muted-border-color); border-radius:12px; padding:.6rem .8rem; }
.board h4 { margin:0 0 .3rem; font-size:.95rem; } .board h4 { margin:0 0 .3rem; font-size:.95rem; }
.board table { margin:0; font-size:.85rem; } .board ol { list-style:none; margin:0; padding:0; }
.board td, .board th { padding:.2rem .35rem; } .board li { list-style:none; display:grid; grid-template-columns:1.6rem minmax(0, 1fr) var(--nw, 4.6rem); align-items:center; gap:.5rem;
.board td.n { text-align:right; font-variant-numeric:tabular-nums; } height:2rem; margin:0; padding:0 .2rem; border-bottom:1px solid var(--pico-muted-border-color); font-size:.88rem; }
.board td.r { width:1.6em; color:var(--pico-muted-color); } .board li:last-child { border-bottom:0; }
.board a { text-decoration:none; } .board .r { color:var(--pico-muted-color); text-align:right; font-variant-numeric:tabular-nums; }
.board .who { display:flex; align-items:center; gap:.4rem; min-width:0; }
.board .who a { text-decoration:none; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; min-width:0; }
.board .lvl { flex:none; font-size:.66rem; padding:.02rem .45rem; border-radius:99px; border:1px solid var(--pico-muted-border-color);
color:var(--pico-muted-color); white-space:nowrap; }
.board .n { text-align:right; font-variant-numeric:tabular-nums; white-space:nowrap; }
/* points: the main board, twice as wide, level in its own column so the pills line up */
.board.wide { grid-column:span 2; }
.board.wide li { grid-template-columns:1.6rem minmax(0, 1fr) 8.5rem var(--nw, 4.6rem); }
.board.wide .lvl { justify-self:start; }
@media (max-width: 700px) { .board.wide { grid-column:auto; } }
.emotes { display:flex; flex-wrap:wrap; gap:.5rem; } .emotes { display:flex; flex-wrap:wrap; gap:.5rem; }
.emote { display:flex; align-items:center; gap:.35rem; border:1px solid var(--pico-muted-border-color); border-radius:99px; padding:.15rem .6rem .15rem .25rem; font-size:.8rem; } .emote { display:flex; align-items:center; gap:.35rem; border:1px solid var(--pico-muted-border-color); border-radius:99px; padding:.15rem .6rem .15rem .25rem; font-size:.8rem; }
.emote img { width:26px; height:26px; object-fit:contain; } .emote img { width:26px; height:26px; object-fit:contain; }
@ -89,20 +99,22 @@
<h3>Leaderboards</h3> <h3>Leaderboards</h3>
<% <%
const board = (title, rows, fmt, extra) => { const board = (title, rows, fmt, extra, nw) => {
let s = `<div class="board"><h4>${title}</h4>`; let s = `<div class="board${extra ? ' wide' : ''}"${nw ? ` style="--nw:${nw}"` : ''}><h4>${title}</h4>`;
if (!rows.length) return s + '<p class="empty">nothing yet</p></div>'; if (!rows.length) return s + '<p class="empty">nothing yet</p></div>';
s += '<table>'; s += '<ol>';
rows.forEach((r, i) => { rows.forEach((r, i) => {
s += `<tr><td class="r">${i + 1}</td><td><a href="/stats/viewer?q=${encodeURIComponent(r.login || '')}">${(r.name || r.login || '?').replace(/[<>&"]/g, '')}</a>${extra ? `<br><span class="meta" style="font-size:.75rem;">${extra(r)}</span>` : ''}</td><td class="n">${fmt(r.n)}</td></tr>`; const name = (r.name || r.login || '?').replace(/[<>&"]/g, '');
s += `<li><span class="r">${i + 1}</span><span class="who"><a href="/stats/viewer?q=${encodeURIComponent(r.login || '')}" title="${name}">${name}</a></span>`
+ `${extra ? `<span class="lvl">${extra(r)}</span>` : ''}<span class="n">${fmt(r.n)}</span></li>`;
}); });
return s + '</table></div>'; return s + '</ol></div>';
}; };
const hm = m => m >= 60 ? `${Math.floor(m / 60)} h ${m % 60} m` : `${m} m`; const hm = m => m >= 60 ? `${Math.floor(m / 60)} h ${m % 60} m` : `${m} m`;
%> %>
<div class="boards"> <div class="boards">
<%- board('Points', boards.points, n => n.toLocaleString(), r => r.level) %> <%- board('Points', boards.points, n => n.toLocaleString(), r => r.level) %>
<%- board('Watch time', boards.watch, hm) %> <%- board('Watch time', boards.watch, hm, null, '6.4rem') %>
<%- board('Chat messages', boards.chat, n => n.toLocaleString()) %> <%- board('Chat messages', boards.chat, n => n.toLocaleString()) %>
<%- board('Bits', boards.bits, n => n.toLocaleString()) %> <%- board('Bits', boards.bits, n => n.toLocaleString()) %>
<%- board('Channel points spent', boards.channelPoints, n => n.toLocaleString()) %> <%- board('Channel points spent', boards.channelPoints, n => n.toLocaleString()) %>