Open-source platform for 3D AI agents. Turn text or a photo into a rigged, animated GLB avatar, give it an LLM brain, memory and a wallet, and embed it anywhere with one web component. Remote MCP server, x402 payments, Three.js, browser-native.
JavaScript 3d-generationai-agentsanimationavatardigital-humangenerative-aiglbgltfimage-to-3dllmmcpmcp-servermodel-context-protocolsolanatext-to-3dthreejsweb-componentswebglwebxrx402
<!doctype html>
<html lang="en">
<head>
<script>/* three.ws theme boot — no-flash */(function(){try{var m=localStorage.getItem('twx_theme');var l=m==='auto'?(window.matchMedia&&window.matchMedia('(prefers-color-scheme: light)').matches):m==='light';document.documentElement.setAttribute('data-theme',l?'light':'dark');}catch(e){document.documentElement.setAttribute('data-theme','dark');}})();</script>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, viewport-fit=cover" />
<title data-i18n="rankings.meta_title">Rankings · three.ws</title>
<meta name="description" content="The cross-surface three.ws leaderboard: creators ranked by real creations, remixes received, coin launches, followers, and distance walked. Track your streak and earn badges for showing up." data-i18n-attr="content:rankings.meta_description"/>
<link rel="canonical" href="https://three.ws/rankings" />
<link rel="icon" href="/favicon.ico" sizes="any" />
<link rel="icon" type="image/svg+xml" href="/favicon.svg" />
<link rel="apple-touch-icon" href="/apple-touch-icon.png" />
<link rel="manifest" href="/manifest.webmanifest" />
<link rel="stylesheet" href="/style.css" />
<link rel="stylesheet" href="/nav.css" />
<link rel="stylesheet" href="/footer.css" />
<meta property="og:type" content="website" />
<meta property="og:site_name" content="three.ws" />
<meta property="og:url" content="https://three.ws/rankings" />
<meta property="og:title" content="Rankings · three.ws" data-i18n-attr="content:rankings.meta_og_title"/>
<meta property="og:description" content="Creators ranked by real creations, remixes received, coin launches, followers, and distance walked. One board across every surface." data-i18n-attr="content:rankings.meta_og_description"/>
<meta property="og:image" content="https://three.ws/api/page-og?s=labs&t=Rankings&d=The+cross-surface+three.ws+leaderboard%3A+creators+ranked+by+real+creations%2C+remixes+received%2C+coin+launches%2C+followers%2C+and+distance+walked.+Track+your+streak&p=%2Frankings" />
<meta property="og:image:width" content="1200" />
<meta property="og:image:height" content="630" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="@trythreews" />
<meta name="twitter:title" content="Rankings · three.ws" data-i18n-attr="content:rankings.meta_twitter_title"/>
<meta name="twitter:description" content="Creators ranked by real creations, remixes, launches, followers, and walk distance. One board across every surface." data-i18n-attr="content:rankings.meta_twitter_description"/>
<meta name="twitter:image" content="https://three.ws/api/page-og?s=labs&t=Rankings&d=The+cross-surface+three.ws+leaderboard%3A+creators+ranked+by+real+creations%2C+remixes+received%2C+coin+launches%2C+followers%2C+and+distance+walked.+Track+your+streak&p=%2Frankings" />
<meta name="theme-color" content="#0a0a0a" />
<style>
.rk-shell { max-width: 980px; margin: 0 auto; padding: var(--space-lg) var(--space-md) var(--space-2xl); }
.rk-hero { padding: var(--space-xl) 0 var(--space-md); }
.rk-kicker {
display: inline-flex; align-items: center; gap: var(--space-xs);
font: var(--weight-semibold) var(--text-2xs)/1.2 var(--font-mono);
letter-spacing: 0.06em; text-transform: uppercase; color: var(--color-text-dim);
margin: 0 0 var(--space-sm);
}
.rk-live-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--color-success); box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-success) 60%, transparent); animation: rk-pulse 1.8s ease infinite; }
@keyframes rk-pulse { 0%,100% { box-shadow: 0 0 0 0 color-mix(in srgb, var(--color-success) 55%, transparent); } 70% { box-shadow: 0 0 0 6px transparent; } }
.rk-title { font: var(--weight-bold) var(--text-2xl)/1.05 var(--font-display); color: var(--color-text-bright); margin: 0 0 var(--space-sm); letter-spacing: -0.02em; }
.rk-sub { font: var(--weight-regular) var(--text-base)/var(--leading-normal) var(--font-body); color: var(--color-text-dim); margin: 0; max-width: 62ch; }
/* Your streak card */
.rk-streak-card {
display: none;
align-items: center; gap: var(--space-md);
margin: var(--space-lg) 0 0;
padding: var(--space-md);
border: 1px solid var(--color-border);
border-radius: var(--radius-lg);
background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 10%, var(--surface-1)), var(--surface-1));
}
.rk-streak-card.is-visible { display: flex; }
.rk-streak-flame { font-size: 28px; line-height: 1; flex: none; }
.rk-streak-body { flex: 1; min-width: 0; }
.rk-streak-num { font: var(--weight-bold) var(--text-xl)/1.1 var(--font-display); color: var(--color-text-bright); }
.rk-streak-label { font: var(--weight-medium) var(--text-sm)/1.3 var(--font-body); color: var(--color-text-dim); margin-top: 2px; }
.rk-streak-badges { display: flex; gap: var(--space-2xs); flex-wrap: wrap; }
.rk-badge-chip {
display: inline-flex; align-items: center; gap: 4px;
padding: 4px 9px; border-radius: var(--radius-pill);
background: var(--surface-2); border: 1px solid var(--color-border);
font: var(--weight-medium) var(--text-2xs)/1 var(--font-body); color: var(--color-text);
white-space: nowrap;
}
.rk-controls { display: flex; flex-wrap: wrap; gap: var(--space-sm); align-items: center; margin: var(--space-lg) 0 var(--space-md); }
.rk-seg { display: inline-flex; flex-wrap: wrap; gap: var(--space-3xs); padding: var(--space-3xs); background: var(--surface-1); border: 1px solid var(--color-border); border-radius: var(--radius-pill); }
.rk-seg-btn {
appearance: none; border: 0; background: transparent; cursor: pointer;
padding: var(--space-xs) var(--space-md); border-radius: var(--radius-pill);
font: var(--weight-medium) var(--text-md)/1 var(--font-body); color: var(--color-text-dim);
transition: color var(--duration-fast) var(--ease-standard), background var(--duration-fast) var(--ease-standard);
white-space: nowrap;
}
.rk-seg-btn:hover { color: var(--color-text); }
.rk-seg-btn:active { transform: scale(0.97); }
.rk-seg-btn.is-active { background: var(--surface-3); color: var(--color-text-bright); }
.rk-seg-btn:focus-visible { outline: var(--focus-ring-width) solid var(--focus-ring-color); outline-offset: var(--focus-ring-offset); }
@media (prefers-reduced-motion: reduce) { .rk-seg-btn:active { transform: none; } }
.rk-board { border: 1px solid var(--color-border); border-radius: var(--radius-lg); background: var(--surface-1); overflow: hidden; }
.rk-head, .rk-row {
display: grid;
grid-template-columns: 56px 1fr 140px;
align-items: center; gap: var(--space-sm);
padding: var(--space-sm) var(--space-md);
}
.rk-head { background: var(--surface-2); border-bottom: 1px solid var(--color-border); font: var(--weight-semibold) var(--text-2xs)/1 var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-faint); }
.rk-col-num { text-align: right; }
.rk-row { border-bottom: 1px solid var(--color-border); transition: background var(--duration-fast) var(--ease-standard); }
.rk-row:last-child { border-bottom: 0; }
.rk-row:hover { background: var(--surface-2); }
.rk-rank { font: var(--weight-bold) var(--text-md)/1 var(--font-mono); color: var(--color-text-dim); }
.rk-rank.is-top { color: var(--color-text-bright); }
.rk-medal { font-size: 16px; }
.rk-creator { display: flex; align-items: center; gap: var(--space-sm); min-width: 0; }
.rk-avatar { width: 34px; height: 34px; border-radius: 50%; object-fit: cover; background: var(--surface-3); flex: none; border: 1px solid var(--color-border); }
.rk-avatar-fallback { display: flex; align-items: center; justify-content: center; font: var(--weight-semibold) var(--text-sm)/1 var(--font-body); color: var(--color-text-dim); }
.rk-handle { font: var(--weight-medium) var(--text-md)/1.2 var(--font-body); color: var(--color-text); text-decoration: none; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
a.rk-handle:hover { color: var(--color-text-bright); text-decoration: underline; }
a.rk-handle:active { color: var(--accent); }
a.rk-handle:focus-visible { outline: var(--focus-ring-width) solid var(--focus-ring-color); outline-offset: var(--focus-ring-offset); border-radius: var(--radius-sm); }
.rk-you { flex: none; padding: 2px 7px; border-radius: var(--radius-pill); background: color-mix(in srgb, var(--accent) 18%, transparent); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); color: var(--color-text-bright); font: var(--weight-semibold) var(--text-2xs)/1 var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; }
.rk-value { font: var(--weight-semibold) var(--text-md)/1 var(--font-mono); color: var(--color-text-bright); text-align: right; }
.rk-rank.is-unranked { font-size: var(--text-2xs); letter-spacing: 0.04em; color: var(--color-text-faint); }
.rk-me { position: sticky; bottom: 0; z-index: 5; margin-top: var(--space-md); border: 1px solid color-mix(in srgb, var(--accent) 28%, var(--color-border)); border-radius: var(--radius-lg); background: var(--surface-3); backdrop-filter: blur(var(--blur-md)); -webkit-backdrop-filter: blur(var(--blur-md)); box-shadow: var(--shadow-2); }
.rk-me .rk-row { border-bottom: 0; }
.rk-me-tag { font: var(--weight-semibold) var(--text-2xs)/1 var(--font-mono); text-transform: uppercase; letter-spacing: 0.06em; color: var(--color-text-faint); padding: var(--space-xs) var(--space-md) 0; }
.rk-loadmore { display: block; margin: var(--space-md) auto 0; appearance: none; cursor: pointer; padding: var(--space-sm) var(--space-lg); border-radius: var(--radius-md); border: 1px solid var(--color-border); background: var(--surface-1); color: var(--color-text); font: var(--weight-medium) var(--text-md)/1 var(--font-body); transition: background var(--duration-fast) var(--ease-standard); }
.rk-loadmore:hover { background: var(--surface-2); }
.rk-loadmore:active { background: var(--surface-3); }
.rk-loadmore:focus-visible { outline: var(--focus-ring-width) solid var(--focus-ring-color); outline-offset: var(--focus-ring-offset); }
.rk-loadmore[disabled] { opacity: var(--disabled-opacity); cursor: var(--disabled-cursor); }
.rk-more-error { margin: var(--space-sm) auto 0; max-width: 46ch; text-align: center; font: var(--weight-regular) var(--text-sm)/var(--leading-normal) var(--font-body); color: var(--color-danger, var(--color-text-dim)); }
.rk-state { padding: var(--space-2xl) var(--space-md); text-align: center; }
.rk-state-title { font: var(--weight-semibold) var(--text-lg)/1.2 var(--font-display); color: var(--color-text-bright); margin: 0 0 var(--space-xs); }
.rk-state-msg { font: var(--weight-regular) var(--text-md)/var(--leading-normal) var(--font-body); color: var(--color-text-dim); margin: 0 auto var(--space-md); max-width: 46ch; }
.rk-state .rk-cta { display: inline-flex; align-items: center; gap: var(--space-xs); padding: var(--space-sm) var(--space-lg); border-radius: var(--radius-md); background: var(--accent); color: var(--bg-0); font: var(--weight-semibold) var(--text-md)/1 var(--font-body); text-decoration: none; transition: opacity var(--duration-fast) var(--ease-standard); }
.rk-state .rk-cta:hover { opacity: 0.85; }
.rk-state .rk-cta:active { opacity: 0.7; }
.rk-state .rk-cta:focus-visible { outline: var(--focus-ring-width) solid var(--focus-ring-color); outline-offset: var(--focus-ring-offset); }
.rk-state-detail { font: var(--weight-regular) var(--text-2xs)/1.4 var(--font-mono); color: var(--color-text-faint); margin: var(--space-sm) 0 0; }
.rk-skel-row { display: grid; grid-template-columns: 56px 1fr 140px; gap: var(--space-sm); align-items: center; padding: var(--space-sm) var(--space-md); border-bottom: 1px solid var(--color-border); }
.rk-skel { height: 14px; border-radius: var(--radius-sm); background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 37%, var(--surface-2) 63%); background-size: 400% 100%; animation: rk-shimmer 1.4s ease infinite; }
.rk-skel.circle { width: 34px; height: 34px; border-radius: 50%; }
@keyframes rk-shimmer { 0% { background-position: 100% 0; } 100% { background-position: -100% 0; } }
@media (prefers-reduced-motion: reduce) { .rk-skel, .rk-live-dot { animation: none; } }
.rk-footer-links { display: flex; flex-wrap: wrap; gap: var(--space-sm); margin-top: var(--space-lg); }
.rk-footer-links a { font: var(--weight-medium) var(--text-sm)/1 var(--font-body); color: var(--color-text-dim); text-decoration: none; padding: var(--space-xs) var(--space-md); border: 1px solid var(--color-border); border-radius: var(--radius-pill); transition: color var(--duration-fast) var(--ease-standard), border-color var(--duration-fast) var(--ease-standard); }
.rk-footer-links a:hover { color: var(--color-text-bright); border-color: var(--color-text-dim); }
.rk-footer-links a:active { background: var(--surface-2); }
.rk-footer-links a:focus-visible { outline: var(--focus-ring-width) solid var(--focus-ring-color); outline-offset: var(--focus-ring-offset); }
.sr-only {
position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0;
}
@media (max-width: 640px) {
.rk-head, .rk-row, .rk-skel-row { grid-template-columns: 40px 1fr 96px; }
.rk-title { font-size: var(--text-xl); }
}
</style>
<meta name="robots" content="index, follow, max-image-preview:large, max-snippet:-1">
<meta property="og:locale" content="en_US">
<meta property="og:image:alt" content="Rankings · three.ws">
<script type="application/ld+json">{"@context":"https://schema.org","@graph":[{"@type":"WebPage","name":"Rankings","description":"The cross-surface three.ws leaderboard: creations, remixes, launches, followers, and walk distance, ranked.","url":"https://three.ws/rankings","isPartOf":{"@type":"WebSite","name":"three.ws","url":"https://three.ws"}}]}</script>
</head>
<body>
<header><div id="nav-container"></div></header>
<script src="/nav.js"></script>
<main class="rk-shell" aria-labelledby="rk-title">
<section class="rk-hero">
<p class="rk-kicker" data-i18n-html="rankings.cross_surface_updates_live"><span class="rk-live-dot" aria-hidden="true"></span> Cross-surface · updates live</p>
<h1 id="rk-title" class="rk-title" data-i18n="rankings.rankings">Rankings</h1>
<p class="rk-sub" data-i18n="rankings.one_board_across_every_surface_creations_for">One board across every surface: creations forged, remixes earned, coins launched, creators followed, and distance walked. Show up daily to build a streak and earn badges.</p>
</section>
<div class="rk-streak-card" id="rk-streak-card">
<div class="rk-streak-flame" aria-hidden="true">🔥</div>
<div class="rk-streak-body">
<div class="rk-streak-num" id="rk-streak-num">0-day streak</div>
<div class="rk-streak-label" id="rk-streak-label">Come back tomorrow to keep it alive</div>
<div class="rk-streak-badges" id="rk-streak-badges"></div>
</div>
</div>
<section class="rk-controls" aria-label="Leaderboard metric">
<div class="rk-seg" role="tablist" aria-label="Rank by" id="rk-metric">
<button class="rk-seg-btn is-active" data-metric="creations" role="tab" aria-selected="true" aria-controls="rk-board" data-i18n="rankings.creations">Creations</button>
<button class="rk-seg-btn" data-metric="remixes_received" role="tab" aria-selected="false" aria-controls="rk-board" tabindex="-1" data-i18n="rankings.remixes">Remixes</button>
<button class="rk-seg-btn" data-metric="launches" role="tab" aria-selected="false" aria-controls="rk-board" tabindex="-1" data-i18n="rankings.launches">Launches</button>
<button class="rk-seg-btn" data-metric="followers" role="tab" aria-selected="false" aria-controls="rk-board" tabindex="-1" data-i18n="rankings.followers">Followers</button>
<button class="rk-seg-btn" data-metric="walk_distance" role="tab" aria-selected="false" aria-controls="rk-board" tabindex="-1" data-i18n="rankings.walk_distance">Walk Distance</button>
<button class="rk-seg-btn" data-metric="ufo_score" role="tab" aria-selected="false" aria-controls="rk-board" tabindex="-1" data-i18n="rankings.ufo_score">UFO High Score</button>
</div>
</section>
<section class="rk-board" id="rk-board" role="tabpanel" tabindex="0" aria-label="Ranked creators" aria-busy="true">
<div class="rk-head" aria-hidden="true">
<span>#</span>
<span data-i18n="rankings.creator">Creator</span>
<span class="rk-col-num" id="rk-metric-label" data-i18n="rankings.creations_2">Creations</span>
</div>
<div id="rk-rows"></div>
</section>
<p id="rk-status" class="sr-only" role="status" aria-live="polite"></p>
<button type="button" id="rk-loadmore" class="rk-loadmore" hidden data-i18n="rankings.show_more">Show more</button>
<p id="rk-more-error" class="rk-more-error" role="status" hidden></p>
<div id="rk-me-wrap" class="rk-me" hidden>
<div class="rk-me-tag" data-i18n="rankings.your_rank" data-i18n-owned="1">Your rank</div>
<div id="rk-me-row"></div>
</div>
<nav class="rk-footer-links" aria-label="Other leaderboards">
<a href="/leaderboard" data-i18n="rankings.trader_leaderboard">Trader Leaderboard →</a>
<a href="/walk-leaderboard" data-i18n="rankings.walk_leaderboard">Walk Leaderboard →</a>
<a href="/creations" data-i18n="rankings.remix_bazaar">Remix Bazaar →</a>
</nav>
</main>
<script src="/brand.js" defer></script>
<div id="footer-container"></div>
<script src="/footer.js"></script>
<script type="module">
const rowsEl = document.getElementById('rk-rows');
const boardEl = rowsEl.closest('.rk-board');
const metricLabelEl = document.getElementById('rk-metric-label');
const loadMoreEl = document.getElementById('rk-loadmore');
const meWrap = document.getElementById('rk-me-wrap');
const meRow = document.getElementById('rk-me-row');
const meTag = meWrap.querySelector('.rk-me-tag');
const metricSeg = document.getElementById('rk-metric');
const moreErrorEl = document.getElementById('rk-more-error');
const statusEl = document.getElementById('rk-status');
const streakCard = document.getElementById('rk-streak-card');
const streakNum = document.getElementById('rk-streak-num');
const streakLabel = document.getElementById('rk-streak-label');
const streakBadges = document.getElementById('rk-streak-badges');
const METRIC_HEAD = {
creations: 'Creations',
remixes_received: 'Remixes',
launches: 'Launches',
followers: 'Followers',
walk_distance: 'Distance',
ufo_score: 'Score',
};
const EMPTY_COPY = {
creations: { title: 'No creations ranked yet', msg: 'Forge a 3D model or build a world while signed in, and it’ll show up here.', cta: { href: '/forge', label: 'Start creating →' } },
remixes_received: { title: 'No remixes yet', msg: 'Publish one of your creations to the remix bazaar and wait for another creator to build on it.', cta: { href: '/creations', label: 'Open the bazaar →' } },
launches: { title: 'No launches ranked yet', msg: 'Launch a coin from one of your agents to show up here.', cta: { href: '/create-agent', label: 'Launch an agent →' } },
followers: { title: 'No one ranked yet', msg: 'Grow your following by sharing your profile and creations.', cta: { href: '/feed', label: 'Open your feed →' } },
walk_distance: { title: 'No walkers ranked yet', msg: 'Sign in and take your avatar for a walk. Distance while signed in counts here.', cta: { href: '/walk', label: 'Start walking →' } },
ufo_score: { title: 'No pilots ranked yet', msg: 'Sign in, fly Flappin UFO, and post a score. Your best verified run counts here.', cta: { href: '/play/ufo', label: 'Play Flappin UFO →' } },
};
const PAGE = 50;
// Without a ceiling a stalled API leaves the board shimmering forever:
// the skeleton is indistinguishable from a request that will never
// answer. A timeout routes that case into the designed error state,
// which already carries a Retry button.
const REQUEST_TIMEOUT_MS = 15000;
let state = { metric: 'creations', offset: 0, total: 0, loading: false };
// Every fetch carries a sequence number and its own AbortController. A
// metric switch mid-flight aborts the old request and bumps the sequence,
// so a late response can never paint the wrong metric over the new one.
// The previous guard dropped the click outright, which left the selected
// tab and the rendered board permanently disagreeing.
let requestSeq = 0;
let inflight = null;
const esc = (s) => String(s).replace(/[<>&"']/g, (c) => ({ '<': '<', '>': '>', '&': '&', '"': '"', "'": ''' }[c]));
function fmtValue(metric, v) {
if (metric === 'walk_distance') return v >= 1000 ? (v / 1000).toFixed(2) + ' km' : Math.round(v) + ' m';
return String(Math.round(v));
}
function medal(rank) {
if (rank === 1) return '<span class="rk-medal" aria-hidden="true">🥇</span>';
if (rank === 2) return '<span class="rk-medal" aria-hidden="true">🥈</span>';
if (rank === 3) return '<span class="rk-medal" aria-hidden="true">🥉</span>';
return '';
}
function avatarCell(r) {
if (r.avatar) return `<img class="rk-avatar" src="${esc(r.avatar)}" alt="" loading="lazy" />`;
const ch = esc((r.handle || '?').replace(/^@/, '')[0] || '?').toUpperCase();
return `<span class="rk-avatar rk-avatar-fallback" aria-hidden="true">${ch}</span>`;
}
function rowHtml(r, metric, isMe, { pinned = false } = {}) {
// The you-marker rides beside the handle rather than inside its text so
// it survives the linked case: a signed-in creator with a public profile
// gets an <a>, and inlining "(you)" there dropped it for exactly the
// users most likely to be looking for themselves.
const handle = r.profileUrl
? `<a class="rk-handle" href="${esc(r.profileUrl)}">${esc(r.handle)}</a>`
: `<span class="rk-handle">${esc(r.handle)}</span>`;
// Inside the pinned "Your rank" card the chip and a spelled-out rank are
// both redundant with the card's own label, and at 320px they crowded the
// handle down to a single character. The card carries that copy instead.
const you = isMe && !pinned ? '<span class="rk-you">You</span>' : '';
const unranked = r.rank == null;
const rankCls = unranked ? 'rk-rank is-unranked' : r.rank <= 3 ? 'rk-rank is-top' : 'rk-rank';
const rankText = unranked ? (pinned ? '' : 'Unranked') : (medal(r.rank) || '#' + r.rank);
return `
<div class="rk-row">
<span class="${rankCls}">${rankText}</span>
<span class="rk-creator">${avatarCell(r)} ${handle}${you}</span>
<span class="rk-value">${fmtValue(metric, r.value)}</span>
</div>`;
}
function skeleton() {
let h = '';
for (let i = 0; i < 8; i++) {
h += `<div class="rk-skel-row"><span class="rk-skel" style="width:24px"></span><span style="display:flex;align-items:center;gap:10px"><span class="rk-skel circle"></span><span class="rk-skel" style="width:120px"></span></span><span class="rk-skel" style="width:70px;justify-self:end"></span></div>`;
}
rowsEl.innerHTML = h;
}
function announce(text) {
statusEl.textContent = text;
}
function showState(copy) {
rowsEl.innerHTML = `<div class="rk-state"><p class="rk-state-title">${esc(copy.title)}</p><p class="rk-state-msg">${esc(copy.msg)}</p>${copy.cta ? `<a class="rk-cta" href="${esc(copy.cta.href)}">${esc(copy.cta.label)}</a>` : ''}</div>`;
announce(copy.title);
}
function showError(detail) {
const wrap = document.createElement('div');
wrap.className = 'rk-state';
wrap.innerHTML =
`<p class="rk-state-title">Couldn't load the leaderboard</p>` +
`<p class="rk-state-msg">The rankings service didn't answer. Check your connection and try again; every board is rebuilt from live data, so nothing is lost.</p>`;
const btn = document.createElement('button');
btn.className = 'rk-cta';
btn.type = 'button';
btn.textContent = 'Retry';
btn.addEventListener('click', () => load({ reset: true }));
wrap.appendChild(btn);
if (detail) {
const p = document.createElement('p');
p.className = 'rk-state-detail';
p.textContent = detail;
wrap.appendChild(p);
}
rowsEl.replaceChildren(wrap);
announce("Couldn't load the leaderboard. Use the retry button to try again.");
}
function renderMe(me, metric) {
if (!me) { meWrap.hidden = true; return; }
meWrap.hidden = false;
meTag.textContent = me.rank == null ? 'Your rank · not ranked yet' : 'Your rank';
meRow.innerHTML = rowHtml(me, metric, true, { pinned: true });
}
// The streak card needs no username and no second endpoint: /api/leaderboard/unified
// returns the viewer's streak and badges alongside the board.
function renderStreak(streak, badges) {
if (!streak) { streakCard.classList.remove('is-visible'); return; }
streakCard.classList.add('is-visible');
const days = streak.currentStreak || 0;
streakNum.textContent = days === 1 ? '1-day streak' : `${days}-day streak`;
streakLabel.textContent = days > 0
? `Come back tomorrow to keep it alive. Longest so far: ${streak.longestStreak || days} days.`
: 'Create, launch, or walk today to start one.';
const list = (badges || []).slice(0, 4);
streakBadges.innerHTML = list.length
? list.map((b) => `<span class="rk-badge-chip" title="${esc(b.description || '')}">${esc(b.icon || '\u2605')} ${esc(b.label || b.code)}</span>`).join('')
: '<span class="rk-badge-chip">\u2605 No badges yet</span>';
}
async function load({ reset = true } = {}) {
if (!reset && state.loading) return;
if (inflight) inflight.abort();
const ctrl = new AbortController();
inflight = ctrl;
const seq = ++requestSeq;
const isCurrent = () => seq === requestSeq;
// A metric switch aborts the previous request too, so the two cases
// have to stay distinguishable: a user-driven abort is silent, a
// timeout is a real failure the viewer needs to see.
let timedOut = false;
const timer = setTimeout(() => { timedOut = true; ctrl.abort(); }, REQUEST_TIMEOUT_MS);
state.loading = true;
if (reset) {
state.offset = 0;
skeleton();
meWrap.hidden = true;
loadMoreEl.hidden = true;
}
moreErrorEl.hidden = true;
boardEl.setAttribute('aria-busy', 'true');
loadMoreEl.disabled = true;
const params = new URLSearchParams({ metric: state.metric, limit: String(PAGE), offset: String(state.offset) });
try {
const res = await fetch('/api/leaderboard/unified?' + params.toString(), { credentials: 'include', signal: ctrl.signal });
if (!res.ok) throw new Error('HTTP ' + res.status);
const data = await res.json();
if (!isCurrent()) return;
state.total = data.total || 0;
const metric = data.metric || state.metric;
metricLabelEl.textContent = METRIC_HEAD[metric] || 'Value';
renderStreak(data.streak, data.badges);
if (reset && (!data.rows || !data.rows.length)) {
showState(EMPTY_COPY[metric] || { title: 'No one ranked yet', msg: 'Be the first.' });
loadMoreEl.hidden = true;
renderMe(data.me, metric);
return;
}
const html = (data.rows || []).map((r) => rowHtml(r, metric, data.me && r.userId === data.me.userId)).join('');
if (reset) rowsEl.innerHTML = html; else rowsEl.insertAdjacentHTML('beforeend', html);
state.offset += (data.rows || []).length;
loadMoreEl.hidden = !data.hasMore;
renderMe(data.me, metric);
const label = METRIC_HEAD[metric] || 'Value';
announce(`${label}: showing ${state.offset} of ${state.total} ranked creators.`);
} catch (err) {
if (err?.name === 'AbortError' && !timedOut) return;
if (!isCurrent()) return;
const detail = timedOut
? `No response in ${Math.round(REQUEST_TIMEOUT_MS / 1000)}s`
: err?.message || 'Unknown error';
if (reset) {
loadMoreEl.hidden = true;
showError(detail);
} else {
// A silent no-op on "Show more" reads as a dead button. Say what
// happened and leave the already-loaded rows in place.
moreErrorEl.textContent = `Couldn't load more (${detail}). Tap Show more to try again.`;
moreErrorEl.hidden = false;
}
} finally {
clearTimeout(timer);
if (isCurrent()) {
state.loading = false;
inflight = null;
boardEl.setAttribute('aria-busy', 'false');
loadMoreEl.disabled = false;
}
}
}
function bindSeg(seg, key, onChange) {
const buttons = () => [...seg.querySelectorAll('.rk-seg-btn')];
function select(btn) {
if (!btn || btn.classList.contains('is-active')) return;
// Roving tabindex: exactly one tab is in the tab order, arrow keys
// move between them. Without it a keyboard user tabs through all
// five before reaching the board.
buttons().forEach((b) => {
b.classList.remove('is-active');
b.setAttribute('aria-selected', 'false');
b.tabIndex = -1;
});
btn.classList.add('is-active');
btn.setAttribute('aria-selected', 'true');
btn.tabIndex = 0;
state[key] = btn.dataset[key];
onChange();
}
seg.addEventListener('click', (e) => select(e.target.closest('.rk-seg-btn')));
seg.addEventListener('keydown', (e) => {
const btns = buttons();
let next = null;
if (e.key === 'ArrowRight' || e.key === 'ArrowLeft') {
const i = btns.findIndex((b) => b.classList.contains('is-active'));
next = btns[(i + (e.key === 'ArrowRight' ? 1 : btns.length - 1)) % btns.length];
} else if (e.key === 'Home') next = btns[0];
else if (e.key === 'End') next = btns[btns.length - 1];
if (!next) return;
e.preventDefault();
next.focus();
select(next);
});
}
bindSeg(metricSeg, 'metric', () => load({ reset: true }));
loadMoreEl.addEventListener('click', () => load({ reset: false }));
// Deep links (/rankings?metric=ufo_score) open on that board.
const wanted = new URLSearchParams(location.search).get('metric');
const wantedBtn = wanted && metricSeg.querySelector(`.rk-seg-btn[data-metric="${CSS.escape(wanted)}"]`);
if (wantedBtn && !wantedBtn.classList.contains('is-active')) {
wantedBtn.click();
} else {
load({ reset: true });
}
</script>
<!-- Runtime i18n: detects locale, swaps annotated copy, mounts <lang-switcher>. -->
<script type="module" src="/i18n.js"></script>
</body>
</html>