2026-06-26 12:28:36 -05:00
|
|
|
|
/* ---- Shared: header / footer ---- */
|
|
|
|
|
|
function loadHTML(file, elementId, callback) {
|
|
|
|
|
|
fetch(file)
|
|
|
|
|
|
.then(r => r.text())
|
|
|
|
|
|
.then(html => {
|
|
|
|
|
|
document.getElementById(elementId).innerHTML = html;
|
|
|
|
|
|
if (callback) callback();
|
|
|
|
|
|
})
|
|
|
|
|
|
.catch(err => console.error('Error loading:', file, err));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function highlightActiveNav() {
|
|
|
|
|
|
const current = location.pathname.split('/').pop() || 'index.html';
|
|
|
|
|
|
document.querySelectorAll('#header a[href]').forEach(link => {
|
|
|
|
|
|
if (link.getAttribute('href') === `/${current}`) {
|
|
|
|
|
|
link.classList.add('active');
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-26 17:34:48 -05:00
|
|
|
|
function startCarousel() {
|
|
|
|
|
|
const slides = document.querySelectorAll('#hero-carousel .carousel-slide');
|
|
|
|
|
|
if (!slides.length) return;
|
|
|
|
|
|
let current = 0;
|
|
|
|
|
|
slides[current].style.opacity = '1';
|
|
|
|
|
|
setInterval(() => {
|
|
|
|
|
|
slides[current].style.opacity = '0';
|
|
|
|
|
|
current = (current + 1) % slides.length;
|
|
|
|
|
|
slides[current].style.opacity = '1';
|
|
|
|
|
|
}, 5000);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
loadHTML('/header.html', 'header', () => {
|
|
|
|
|
|
highlightActiveNav();
|
|
|
|
|
|
startCarousel();
|
|
|
|
|
|
});
|
2026-06-26 12:28:36 -05:00
|
|
|
|
loadHTML('/footer.html', 'footer');
|
|
|
|
|
|
|
|
|
|
|
|
/* ============================================================
|
|
|
|
|
|
CONFIG — the only block you edit
|
|
|
|
|
|
============================================================ */
|
|
|
|
|
|
const CONFIG = {
|
2026-07-01 09:34:17 -05:00
|
|
|
|
teamId: "2iGDVMgX0a",
|
|
|
|
|
|
leagueId: "BYaaUfKum7z0",
|
|
|
|
|
|
regionId: "VgQKgqmTPU",
|
|
|
|
|
|
lmcLeagueId: "cY0LeCAPfyiG",
|
2026-06-26 12:28:36 -05:00
|
|
|
|
|
2026-06-26 17:34:48 -05:00
|
|
|
|
// Fallback roster if the team endpoint requires auth.
|
|
|
|
|
|
memberIds: [],
|
2026-06-26 12:28:36 -05:00
|
|
|
|
|
|
|
|
|
|
// Flip to true to preview the layout with placeholder rows (no network).
|
|
|
|
|
|
useSample: false,
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const API = "https://newprod-api.bestcoastpairings.com/v1";
|
|
|
|
|
|
const HEADERS = { "client-id": "web-app", "env": "bcp", "accept": "application/json" };
|
2026-06-26 17:34:48 -05:00
|
|
|
|
const CACHE_KEY = "gg_board_v3";
|
2026-06-26 12:28:36 -05:00
|
|
|
|
|
|
|
|
|
|
const $ = (id) => document.getElementById(id);
|
|
|
|
|
|
const fmtPts = (n) => Number(n || 0).toLocaleString(undefined, { minimumFractionDigits: 1, maximumFractionDigits: 1 });
|
2026-06-26 20:13:08 -05:00
|
|
|
|
const fmtWpct = (w, l, t) => { const g = (+w||0)+(+l||0)+(+t||0); return g ? ((+w||0)/g*100).toFixed(1)+'%' : '—'; };
|
2026-06-26 12:28:36 -05:00
|
|
|
|
const fullName = (u = {}) => [u.firstName, u.lastName].filter(Boolean).join(" ").trim();
|
|
|
|
|
|
|
2026-06-26 21:29:23 -05:00
|
|
|
|
/* ---- Career stats ---- */
|
|
|
|
|
|
const careerData = {}; // userId → { w, l, t } | null (in-flight)
|
|
|
|
|
|
|
|
|
|
|
|
async function fetchCareer(userId) {
|
|
|
|
|
|
const r = await fetch(
|
|
|
|
|
|
`${API}/placings?placingsType=player&userId=${userId}&limit=1000`,
|
|
|
|
|
|
{ headers: HEADERS, credentials: 'omit' }
|
|
|
|
|
|
);
|
2026-06-29 00:00:02 -05:00
|
|
|
|
if (!r.ok) return { w: 0, l: 0, t: 0, events: [] };
|
2026-06-26 21:29:23 -05:00
|
|
|
|
const p = await r.json();
|
|
|
|
|
|
const items = Array.isArray(p) ? p : (p.data || []);
|
|
|
|
|
|
let w = 0, l = 0, t = 0;
|
2026-06-29 00:00:02 -05:00
|
|
|
|
const events = [];
|
2026-06-26 21:29:23 -05:00
|
|
|
|
for (const item of items) {
|
|
|
|
|
|
const v = item.value || item;
|
|
|
|
|
|
if (v.wins != null || v.losses != null) {
|
|
|
|
|
|
w += +(v.wins || 0);
|
|
|
|
|
|
l += +(v.losses || 0);
|
|
|
|
|
|
t += +(v.ties || 0);
|
|
|
|
|
|
}
|
2026-06-29 00:00:02 -05:00
|
|
|
|
const eName = v.event?.name || v.eventName || v.tournament?.name || v.tournamentName || '';
|
|
|
|
|
|
if (eName) events.push(eName);
|
2026-06-26 21:29:23 -05:00
|
|
|
|
}
|
2026-06-29 00:00:02 -05:00
|
|
|
|
return { w, l, t, events };
|
2026-06-26 21:29:23 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function loadCareerStats(kept) {
|
|
|
|
|
|
const toFetch = kept.filter(r => {
|
|
|
|
|
|
const uid = r.userId || r.user?.id;
|
|
|
|
|
|
return uid && !(uid in careerData);
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!toFetch.length) return;
|
|
|
|
|
|
toFetch.forEach(r => { careerData[r.userId || r.user?.id] = null; });
|
|
|
|
|
|
await Promise.allSettled(toFetch.map(async r => {
|
|
|
|
|
|
const uid = r.userId || r.user?.id;
|
|
|
|
|
|
try { careerData[uid] = await fetchCareer(uid); }
|
2026-06-29 00:00:02 -05:00
|
|
|
|
catch { careerData[uid] = { w: 0, l: 0, t: 0, events: [] }; }
|
2026-06-26 21:29:23 -05:00
|
|
|
|
}));
|
|
|
|
|
|
if (lastState) render(lastState);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-29 00:00:02 -05:00
|
|
|
|
/* ---- ELO data (stat-check) ---- */
|
|
|
|
|
|
let eloData; // undefined = loading, null = unavailable, Map = loaded
|
|
|
|
|
|
|
|
|
|
|
|
function normalizeEventName(s) {
|
|
|
|
|
|
return String(s).toLowerCase().replace(/[^a-z0-9 ]/g, '').replace(/\s+/g, ' ').trim();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function eventNamesMatch(a, b) {
|
|
|
|
|
|
const na = normalizeEventName(a), nb = normalizeEventName(b);
|
|
|
|
|
|
if (!na || !nb || na.length < 6 || nb.length < 6) return na === nb;
|
|
|
|
|
|
return na === nb || na.includes(nb) || nb.includes(na);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async function loadEloData() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const r = await fetch('/elo-data.json');
|
|
|
|
|
|
if (!r.ok) { eloData = null; return; }
|
|
|
|
|
|
const d = await r.json();
|
|
|
|
|
|
const map = new Map();
|
|
|
|
|
|
for (const p of (d.players || [])) {
|
|
|
|
|
|
const key = String(p.name || '').toLowerCase();
|
|
|
|
|
|
if (!key) continue;
|
|
|
|
|
|
if (!map.has(key)) map.set(key, []);
|
|
|
|
|
|
map.get(key).push(p);
|
|
|
|
|
|
}
|
|
|
|
|
|
eloData = map;
|
|
|
|
|
|
if (lastState) render(lastState);
|
|
|
|
|
|
} catch { eloData = null; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Returns: undefined = still loading, null = no verified match, object = verified match
|
|
|
|
|
|
function findElo(name, uid) {
|
|
|
|
|
|
if (eloData === undefined) return undefined;
|
|
|
|
|
|
if (!eloData) return null;
|
|
|
|
|
|
const candidates = eloData.get(String(name).toLowerCase()) || [];
|
|
|
|
|
|
if (!candidates.length) return null;
|
|
|
|
|
|
if (uid && !(uid in careerData)) return undefined; // career fetch not started yet
|
|
|
|
|
|
const cd = uid ? careerData[uid] : undefined;
|
|
|
|
|
|
if (cd === null) return undefined; // career in-flight
|
|
|
|
|
|
const events = cd?.events || [];
|
|
|
|
|
|
if (!events.length) return candidates.length === 1 ? candidates[0] : null;
|
|
|
|
|
|
const verified = candidates.filter(c => events.some(e => eventNamesMatch(e, c.lastEvent)));
|
|
|
|
|
|
return verified.length === 1 ? verified[0] : null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-26 20:13:08 -05:00
|
|
|
|
/* ---- Sort state ---- */
|
|
|
|
|
|
let sortState = { col: 'pts', dir: 'desc' };
|
|
|
|
|
|
let lastState = null;
|
|
|
|
|
|
|
|
|
|
|
|
const sortCols = {
|
|
|
|
|
|
pts: { key: r => +(r.ITCPoints || 0), defaultDir: 'desc' },
|
|
|
|
|
|
name: { key: r => fullName(r.user || {}).toLowerCase() || '', defaultDir: 'asc' },
|
2026-06-26 20:16:03 -05:00
|
|
|
|
wlt: { key: r => (+r.wins||0) * 10000 - (+r.losses||0) * 100 - (+r.ties||0), defaultDir: 'desc' },
|
2026-06-26 20:13:08 -05:00
|
|
|
|
wpct: { key: r => { const g=(+r.wins||0)+(+r.losses||0)+(+r.ties||0); return g?(+r.wins||0)/g:-1; }, defaultDir: 'desc' },
|
2026-06-29 00:00:02 -05:00
|
|
|
|
rank: { key: r => +(r.placing || Infinity), defaultDir: 'asc' },
|
2026-07-01 09:38:04 -05:00
|
|
|
|
lmc: { key: r => { const uid = r.userId || r.user?.id; return uid && lmcPoints[uid] != null ? lmcPoints[uid] : -Infinity; }, defaultDir: 'desc' },
|
|
|
|
|
|
lmcrank: { key: r => { const uid = r.userId || r.user?.id; return uid && lmcRanks[uid] != null ? lmcRanks[uid] : Infinity; }, defaultDir: 'asc' },
|
2026-06-29 00:00:02 -05:00
|
|
|
|
elo: { key: r => { const e = findElo(fullName(r.user || {}), r.userId || r.user?.id); return e?.elo ?? -Infinity; }, defaultDir: 'desc' },
|
2026-06-26 20:13:08 -05:00
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
function applySort(rows) {
|
|
|
|
|
|
const { col, dir } = sortState;
|
|
|
|
|
|
const sc = sortCols[col] || sortCols.pts;
|
|
|
|
|
|
return [...rows].sort((a, b) => {
|
|
|
|
|
|
const av = sc.key(a), bv = sc.key(b);
|
|
|
|
|
|
if (typeof av === 'string') return dir === 'asc' ? av.localeCompare(bv) : bv.localeCompare(av);
|
|
|
|
|
|
return dir === 'asc' ? av - bv : bv - av;
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function updateSortHeaders() {
|
|
|
|
|
|
document.querySelectorAll('th[data-sort]').forEach(th => {
|
|
|
|
|
|
const arrow = th.querySelector('.sort-arrow');
|
|
|
|
|
|
if (arrow) arrow.textContent = th.dataset.sort === sortState.col ? (sortState.dir === 'asc' ? ' ▲' : ' ▼') : '';
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function initSortHeaders() {
|
|
|
|
|
|
document.querySelectorAll('th[data-sort]').forEach(th => {
|
|
|
|
|
|
const arrow = document.createElement('span');
|
|
|
|
|
|
arrow.className = 'sort-arrow text-xs opacity-60';
|
|
|
|
|
|
th.appendChild(arrow);
|
|
|
|
|
|
th.addEventListener('click', () => {
|
|
|
|
|
|
const col = th.dataset.sort;
|
|
|
|
|
|
if (sortState.col === col) {
|
|
|
|
|
|
sortState.dir = sortState.dir === 'asc' ? 'desc' : 'asc';
|
|
|
|
|
|
} else {
|
|
|
|
|
|
sortState.col = col;
|
|
|
|
|
|
sortState.dir = (sortCols[col] || sortCols.pts).defaultDir;
|
|
|
|
|
|
}
|
|
|
|
|
|
updateSortHeaders();
|
|
|
|
|
|
if (lastState) render(lastState);
|
|
|
|
|
|
});
|
|
|
|
|
|
});
|
|
|
|
|
|
updateSortHeaders();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-26 12:28:36 -05:00
|
|
|
|
/* ---- Roster ---- */
|
|
|
|
|
|
async function getMemberIds(force) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const r = await fetch(`${API}/teams/${CONFIG.teamId}?expand[]=owner`,
|
2026-06-26 17:34:48 -05:00
|
|
|
|
{ headers: HEADERS, credentials: "omit" });
|
2026-06-26 12:28:36 -05:00
|
|
|
|
if (!r.ok) throw new Error("auth/" + r.status);
|
|
|
|
|
|
let t = await r.json(); if (Array.isArray(t)) t = t[0] || {};
|
|
|
|
|
|
const ids = new Set();
|
|
|
|
|
|
if (Array.isArray(t.memberIds)) t.memberIds.forEach(x => typeof x === "string" && ids.add(x));
|
|
|
|
|
|
if (typeof t.ownerId === "string") ids.add(t.ownerId);
|
|
|
|
|
|
[t.users, t.members, t.teamMembers].forEach(list => {
|
|
|
|
|
|
if (Array.isArray(list)) list.forEach(o => o && o.id && ids.add(o.id));
|
|
|
|
|
|
});
|
|
|
|
|
|
if (t.owner && t.owner.id) ids.add(t.owner.id);
|
2026-06-26 17:34:48 -05:00
|
|
|
|
if (ids.size) return { ids, live: true };
|
2026-06-26 12:28:36 -05:00
|
|
|
|
throw new Error("empty");
|
|
|
|
|
|
} catch (e) {
|
2026-06-26 17:34:48 -05:00
|
|
|
|
if (CONFIG.memberIds.length) return { ids: new Set(CONFIG.memberIds), live: false };
|
2026-06-26 12:28:36 -05:00
|
|
|
|
throw e;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-07-01 09:34:17 -05:00
|
|
|
|
/* ---- LMC Points data ---- */
|
|
|
|
|
|
const lmcPoints = {}; // userId → number
|
2026-07-01 09:38:04 -05:00
|
|
|
|
const lmcRanks = {}; // userId → number
|
2026-07-01 09:34:17 -05:00
|
|
|
|
let lmcLoaded = false;
|
|
|
|
|
|
|
|
|
|
|
|
async function loadLmcData(ids) {
|
|
|
|
|
|
lmcLoaded = false;
|
|
|
|
|
|
try {
|
|
|
|
|
|
for await (const page of streamPlacings(CONFIG.lmcLeagueId)) {
|
|
|
|
|
|
for (const rec of page) {
|
|
|
|
|
|
const uid = rec.userId || rec.user?.id;
|
2026-07-01 09:38:04 -05:00
|
|
|
|
if (uid && ids.has(uid)) {
|
|
|
|
|
|
lmcPoints[uid] = +(rec.ITCPoints || 0);
|
|
|
|
|
|
if (rec.placing != null) lmcRanks[uid] = rec.placing;
|
|
|
|
|
|
}
|
2026-07-01 09:34:17 -05:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
} catch (e) {
|
|
|
|
|
|
console.warn('LMC data load failed:', e);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
lmcLoaded = true;
|
|
|
|
|
|
if (lastState) render(lastState);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2026-06-26 17:34:48 -05:00
|
|
|
|
/* ---- Standings (cursor-paginated, circular-cursor safe) ---- */
|
2026-07-01 09:34:17 -05:00
|
|
|
|
async function* streamPlacings(leagueId, regionId) {
|
|
|
|
|
|
let base = `${API}/placings?placingsType=player&leagueId=${leagueId}&sortAscending=false&limit=1000`;
|
|
|
|
|
|
if (regionId) base += `®ionId=${regionId}`;
|
2026-06-26 17:34:48 -05:00
|
|
|
|
|
|
|
|
|
|
let nextKey = null;
|
|
|
|
|
|
let prevNextKey = undefined;
|
|
|
|
|
|
|
|
|
|
|
|
do {
|
|
|
|
|
|
const url = nextKey ? `${base}&nextKey=${encodeURIComponent(nextKey)}` : base;
|
|
|
|
|
|
const r = await fetch(url, { headers: HEADERS, credentials: "omit" });
|
2026-06-26 12:28:36 -05:00
|
|
|
|
if (!r.ok) throw new Error("placings/" + r.status);
|
|
|
|
|
|
const p = await r.json();
|
2026-06-26 17:34:48 -05:00
|
|
|
|
const page = Array.isArray(p) ? p : (p.data || p.placings || []);
|
|
|
|
|
|
|
|
|
|
|
|
yield page;
|
|
|
|
|
|
|
|
|
|
|
|
const rawKey = p.nextKey;
|
|
|
|
|
|
nextKey = !rawKey ? null
|
|
|
|
|
|
: typeof rawKey === "string" ? rawKey
|
|
|
|
|
|
: btoa(JSON.stringify(rawKey));
|
|
|
|
|
|
|
|
|
|
|
|
// BCP returns the same cursor when there are no more results — stop when it loops
|
|
|
|
|
|
if (nextKey === prevNextKey) break;
|
|
|
|
|
|
prevNextKey = nextKey;
|
|
|
|
|
|
} while (nextKey);
|
2026-06-26 12:28:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ---- Build leaderboard ---- */
|
|
|
|
|
|
function build(rows, ids) {
|
2026-06-26 17:34:48 -05:00
|
|
|
|
const kept = [];
|
2026-06-26 12:28:36 -05:00
|
|
|
|
for (const rec of rows) {
|
2026-06-26 17:34:48 -05:00
|
|
|
|
const uid = rec.userId || (rec.user && rec.user.id);
|
|
|
|
|
|
if (uid && ids.has(uid)) kept.push(rec);
|
2026-06-26 12:28:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
kept.sort((a, b) => Number(b.ITCPoints || 0) - Number(a.ITCPoints || 0));
|
2026-06-26 17:34:48 -05:00
|
|
|
|
return kept;
|
2026-06-26 12:28:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ---- Render ---- */
|
|
|
|
|
|
function render(state) {
|
2026-06-26 20:13:08 -05:00
|
|
|
|
lastState = state;
|
2026-06-26 17:34:48 -05:00
|
|
|
|
const { kept, rosterSize, updated, live, fromCache } = state;
|
2026-06-26 12:28:36 -05:00
|
|
|
|
|
|
|
|
|
|
$("dot").className = "w-2 h-2 rounded-full bg-success animate-pulse transition-colors";
|
|
|
|
|
|
$("updated").textContent = (fromCache ? "Cached " : "Updated ") +
|
|
|
|
|
|
new Date(updated).toLocaleTimeString([], { hour: "2-digit", minute: "2-digit" });
|
2026-06-26 17:34:48 -05:00
|
|
|
|
$("meta").textContent = `${kept.length} of ${rosterSize} members placed` + (live ? "" : " · roster (cached)");
|
2026-06-26 12:28:36 -05:00
|
|
|
|
|
2026-06-26 17:34:48 -05:00
|
|
|
|
$("banner").className = "alert mb-4 hidden";
|
2026-06-26 12:28:36 -05:00
|
|
|
|
|
|
|
|
|
|
const champ = $("champion"), strip = $("strip"), empty = $("empty"), tb = $("rows");
|
|
|
|
|
|
tb.innerHTML = "";
|
|
|
|
|
|
|
|
|
|
|
|
if (!kept.length) {
|
|
|
|
|
|
champ.classList.add("hidden"); strip.hidden = true;
|
|
|
|
|
|
empty.classList.remove("hidden");
|
|
|
|
|
|
empty.textContent = "No Gateway Gamers players found in this league's standings yet. " +
|
|
|
|
|
|
"Once members log games here, they'll appear ranked by ITC points.";
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
empty.classList.add("hidden"); strip.hidden = false;
|
|
|
|
|
|
|
|
|
|
|
|
// Champion card
|
|
|
|
|
|
const top = kept[0], tu = top.user || {};
|
|
|
|
|
|
champ.classList.remove("hidden");
|
|
|
|
|
|
$("champ-name").textContent = fullName(tu) || tu.nickname || "—";
|
2026-06-26 20:13:08 -05:00
|
|
|
|
$("champ-sub").textContent = `${fmtWpct(top.wins, top.losses, top.ties)} Win Rate · ITC #${top.placing ?? "—"}`;
|
2026-06-26 12:28:36 -05:00
|
|
|
|
$("champ-pts").textContent = fmtPts(top.ITCPoints);
|
|
|
|
|
|
|
|
|
|
|
|
// Stat strip
|
|
|
|
|
|
const W = kept.reduce((s, r) => s + (+r.wins || 0), 0),
|
|
|
|
|
|
L = kept.reduce((s, r) => s + (+r.losses || 0), 0),
|
|
|
|
|
|
T = kept.reduce((s, r) => s + (+r.ties || 0), 0),
|
|
|
|
|
|
best = Math.min(...kept.map(r => +r.placing || Infinity));
|
|
|
|
|
|
$("s-placed").textContent = kept.length;
|
|
|
|
|
|
$("s-top").textContent = fmtPts(top.ITCPoints);
|
2026-06-26 20:13:08 -05:00
|
|
|
|
$("s-rec").textContent = fmtWpct(W, L, T);
|
2026-06-26 12:28:36 -05:00
|
|
|
|
$("s-best").textContent = isFinite(best) ? ("#" + best) : "—";
|
|
|
|
|
|
|
2026-06-26 21:29:23 -05:00
|
|
|
|
// Kick off career stat fetches for any players not yet loaded (non-blocking)
|
|
|
|
|
|
loadCareerStats(kept);
|
|
|
|
|
|
|
2026-06-26 12:28:36 -05:00
|
|
|
|
// Rows
|
2026-06-26 20:13:08 -05:00
|
|
|
|
applySort(kept).forEach((r, i) => {
|
2026-06-26 12:28:36 -05:00
|
|
|
|
const u = r.user || {}, name = fullName(u) || u.nickname || "Unknown";
|
2026-06-29 00:07:41 -05:00
|
|
|
|
const uid = r.userId || r.user?.id;
|
|
|
|
|
|
const eloMatch = findElo(name, uid);
|
2026-07-01 09:40:58 -05:00
|
|
|
|
const lmcRankCell = (() => {
|
|
|
|
|
|
if (!lmcLoaded) return `<td class="text-right font-mono text-base-content/40 hidden sm:table-cell"><span class="opacity-20">…</span></td>`;
|
|
|
|
|
|
const rank = uid ? lmcRanks[uid] : undefined;
|
|
|
|
|
|
return `<td class="text-right font-mono text-base-content/40 hidden sm:table-cell">${rank != null ? '#' + rank : '—'}</td>`;
|
|
|
|
|
|
})();
|
2026-06-26 12:28:36 -05:00
|
|
|
|
const tr = document.createElement("tr");
|
|
|
|
|
|
tr.innerHTML =
|
|
|
|
|
|
`<td class="font-mono text-base-content/60">${i === 0 ? `<strong class="text-base-content">1</strong>` : (i + 1)}</td>` +
|
|
|
|
|
|
`<td><span class="font-semibold">${esc(name)}</span>` +
|
2026-06-27 23:35:57 -05:00
|
|
|
|
`${u.nickname && fullName(u) ? `<span class="block text-xs text-base-content/40">"${esc(u.nickname)}"</span>` : ""}` +
|
|
|
|
|
|
`<span class="block text-xs opacity-40 sm:hidden"><span class="text-success">${r.wins || 0}</span>–<span class="text-error">${r.losses || 0}</span>–${r.ties || 0} · ITC #${r.placing ?? "—"}</span>` +
|
|
|
|
|
|
`</td>` +
|
2026-06-26 21:31:13 -05:00
|
|
|
|
(() => {
|
|
|
|
|
|
const d = uid && careerData[uid];
|
|
|
|
|
|
const careerSub = d == null
|
|
|
|
|
|
? `<span class="block text-xs opacity-20">…</span>`
|
|
|
|
|
|
: (d.w + d.l + d.t) === 0 ? ''
|
|
|
|
|
|
: `<span class="block text-xs opacity-40">${d.w}–${d.l}–${d.t} career</span>`;
|
|
|
|
|
|
const careerPct = d == null
|
|
|
|
|
|
? `<span class="block text-xs opacity-20">…</span>`
|
|
|
|
|
|
: (d.w + d.l + d.t) === 0 ? ''
|
|
|
|
|
|
: `<span class="block text-xs opacity-40">${fmtWpct(d.w, d.l, d.t)} career</span>`;
|
2026-06-27 23:35:57 -05:00
|
|
|
|
const mobilePct = `<span class="block text-xs opacity-40 sm:hidden">${fmtWpct(r.wins, r.losses, r.ties)} win rate</span>`;
|
2026-06-29 00:07:41 -05:00
|
|
|
|
const mobileElo = eloMatch ? `<span class="block text-xs opacity-40 sm:hidden">ELO ${Math.round(eloMatch.elo)}</span>` : '';
|
2026-07-01 09:38:04 -05:00
|
|
|
|
const mobileLmc = (() => {
|
|
|
|
|
|
if (!uid || !lmcLoaded || lmcPoints[uid] == null) return '';
|
|
|
|
|
|
const rankStr = lmcRanks[uid] != null ? ` · LMC #${lmcRanks[uid]}` : '';
|
|
|
|
|
|
return `<span class="block text-xs opacity-40 sm:hidden">LMC ${fmtPts(lmcPoints[uid])}${rankStr}</span>`;
|
|
|
|
|
|
})();
|
2026-07-01 09:34:17 -05:00
|
|
|
|
const lmcCell = (() => {
|
|
|
|
|
|
if (!lmcLoaded) return `<td class="text-right font-mono hidden sm:table-cell"><span class="opacity-20">…</span></td>`;
|
|
|
|
|
|
const pts = uid ? lmcPoints[uid] : undefined;
|
|
|
|
|
|
return `<td class="text-right font-mono hidden sm:table-cell">${pts != null ? fmtPts(pts) : '<span class="text-base-content/40">—</span>'}</td>`;
|
|
|
|
|
|
})();
|
2026-06-27 23:35:57 -05:00
|
|
|
|
return `<td class="text-right font-mono font-bold">${fmtPts(r.ITCPoints)}` +
|
2026-07-01 09:34:17 -05:00
|
|
|
|
mobilePct + mobileLmc + mobileElo + `</td>` +
|
|
|
|
|
|
lmcCell +
|
2026-06-27 23:35:57 -05:00
|
|
|
|
`<td class="text-right font-mono hidden sm:table-cell">` +
|
2026-06-26 21:31:13 -05:00
|
|
|
|
`<span class="text-success">${r.wins || 0}</span>–<span class="text-error">${r.losses || 0}</span>–${r.ties || 0}` +
|
|
|
|
|
|
careerSub + `</td>` +
|
|
|
|
|
|
`<td class="text-right font-mono hidden sm:table-cell">${fmtWpct(r.wins, r.losses, r.ties)}` +
|
|
|
|
|
|
careerPct + `</td>`;
|
|
|
|
|
|
})() +
|
2026-06-29 00:00:02 -05:00
|
|
|
|
`<td class="text-right font-mono text-base-content/40 hidden sm:table-cell">#${r.placing ?? "—"}</td>` +
|
2026-07-01 09:39:38 -05:00
|
|
|
|
lmcRankCell +
|
2026-06-29 00:00:02 -05:00
|
|
|
|
(() => {
|
2026-06-29 00:07:41 -05:00
|
|
|
|
if (eloMatch === undefined) return `<td class="text-center font-mono hidden sm:table-cell"><span class="opacity-20">…</span></td>`;
|
|
|
|
|
|
if (!eloMatch) return `<td class="text-center font-mono text-base-content/40 hidden sm:table-cell">—</td>`;
|
|
|
|
|
|
return `<td class="text-center font-mono hidden sm:table-cell">${Math.round(eloMatch.elo)}</td>`;
|
2026-06-29 00:00:02 -05:00
|
|
|
|
})();
|
2026-06-26 12:28:36 -05:00
|
|
|
|
tb.appendChild(tr);
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function esc(s) {
|
|
|
|
|
|
return String(s).replace(/[&<>"]/g, c => ({ "&": "&", "<": "<", ">": ">", '"': """ }[c]));
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ---- Cache ---- */
|
|
|
|
|
|
function paintCache() {
|
|
|
|
|
|
try {
|
|
|
|
|
|
const c = JSON.parse(localStorage.getItem(CACHE_KEY) || "null");
|
|
|
|
|
|
if (c && c.kept) render({ ...c, fromCache: true });
|
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function saveCache(state) {
|
|
|
|
|
|
try {
|
|
|
|
|
|
localStorage.setItem(CACHE_KEY, JSON.stringify({
|
2026-06-26 17:34:48 -05:00
|
|
|
|
kept: state.kept, rosterSize: state.rosterSize, updated: state.updated, live: state.live
|
2026-06-26 12:28:36 -05:00
|
|
|
|
}));
|
|
|
|
|
|
} catch (e) {}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ---- Orchestration ---- */
|
|
|
|
|
|
async function load(force) {
|
|
|
|
|
|
const btn = $("refresh");
|
|
|
|
|
|
btn.disabled = true;
|
|
|
|
|
|
$("dot").className = "w-2 h-2 rounded-full bg-base-content/30 transition-colors";
|
|
|
|
|
|
$("updated").textContent = "Fetching…";
|
|
|
|
|
|
showSkeleton();
|
|
|
|
|
|
try {
|
|
|
|
|
|
if (CONFIG.useSample) { return render({ ...SAMPLE, fromCache: false }); }
|
2026-06-26 17:34:48 -05:00
|
|
|
|
|
|
|
|
|
|
const { ids, live } = await getMemberIds(force);
|
|
|
|
|
|
const allRows = [];
|
|
|
|
|
|
|
2026-07-01 09:34:17 -05:00
|
|
|
|
// Reset and kick off LMC fetch non-blocking
|
|
|
|
|
|
Object.keys(lmcPoints).forEach(k => delete lmcPoints[k]);
|
2026-07-01 09:38:04 -05:00
|
|
|
|
Object.keys(lmcRanks).forEach(k => delete lmcRanks[k]);
|
2026-07-01 09:34:17 -05:00
|
|
|
|
loadLmcData(ids);
|
|
|
|
|
|
|
|
|
|
|
|
for await (const page of streamPlacings(CONFIG.leagueId, CONFIG.regionId)) {
|
2026-06-26 17:34:48 -05:00
|
|
|
|
allRows.push(...page);
|
|
|
|
|
|
// Render incrementally so results appear as pages arrive
|
|
|
|
|
|
const kept = build(allRows, ids);
|
|
|
|
|
|
if (kept.length) render({ kept, rosterSize: ids.size, updated: Date.now(), live, fromCache: false });
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const kept = build(allRows, ids);
|
|
|
|
|
|
const state = { kept, rosterSize: ids.size, updated: Date.now(), live };
|
2026-06-26 12:28:36 -05:00
|
|
|
|
render({ ...state, fromCache: false });
|
|
|
|
|
|
saveCache(state);
|
|
|
|
|
|
} catch (err) {
|
|
|
|
|
|
failure(err);
|
|
|
|
|
|
} finally {
|
|
|
|
|
|
btn.disabled = false;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function showSkeleton() {
|
|
|
|
|
|
const tb = $("rows");
|
|
|
|
|
|
tb.innerHTML = "";
|
|
|
|
|
|
for (let i = 0; i < 6; i++) {
|
|
|
|
|
|
const tr = document.createElement("tr");
|
|
|
|
|
|
tr.innerHTML =
|
|
|
|
|
|
`<td><div class="skeleton h-4 w-5"></div></td>` +
|
2026-06-27 23:35:57 -05:00
|
|
|
|
`<td><div class="skeleton h-4 w-3/5"></div><div class="skeleton h-3 w-2/5 mt-1 sm:hidden"></div></td>` +
|
|
|
|
|
|
`<td><div class="skeleton h-4 w-12 ml-auto"></div><div class="skeleton h-3 w-10 mt-1 ml-auto sm:hidden"></div></td>` +
|
2026-07-01 09:34:17 -05:00
|
|
|
|
`<td class="hidden sm:table-cell"><div class="skeleton h-4 w-12 ml-auto"></div></td>` +
|
2026-06-26 20:15:35 -05:00
|
|
|
|
`<td class="hidden sm:table-cell"><div class="skeleton h-4 w-14 ml-auto"></div></td>` +
|
2026-06-26 12:28:36 -05:00
|
|
|
|
`<td class="hidden sm:table-cell"><div class="skeleton h-4 w-12 ml-auto"></div></td>` +
|
2026-06-29 00:00:02 -05:00
|
|
|
|
`<td class="hidden sm:table-cell"><div class="skeleton h-4 w-10 ml-auto"></div></td>` +
|
2026-07-01 09:39:38 -05:00
|
|
|
|
`<td class="hidden sm:table-cell"><div class="skeleton h-4 w-10 ml-auto"></div></td>` +
|
2026-06-29 00:07:41 -05:00
|
|
|
|
`<td class="hidden sm:table-cell"><div class="skeleton h-4 w-12 mx-auto"></div></td>`;
|
2026-06-26 12:28:36 -05:00
|
|
|
|
tb.appendChild(tr);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function failure(err) {
|
|
|
|
|
|
$("dot").className = "w-2 h-2 rounded-full bg-base-content/30 transition-colors";
|
|
|
|
|
|
$("updated").textContent = "Couldn't update";
|
|
|
|
|
|
$("rows").innerHTML = "";
|
|
|
|
|
|
$("champion").classList.add("hidden");
|
|
|
|
|
|
$("strip").hidden = true;
|
|
|
|
|
|
const b = $("banner");
|
|
|
|
|
|
const msg = String(err.message || err);
|
|
|
|
|
|
b.className = "alert alert-error mb-4";
|
2026-06-26 17:34:48 -05:00
|
|
|
|
b.innerHTML = msg.includes("placings")
|
|
|
|
|
|
? "Couldn't reach the BCP standings feed. Try refreshing, or open the page directly in a browser."
|
|
|
|
|
|
: `Something went wrong: <code class="font-mono text-sm ml-1">${esc(msg)}</code>`;
|
2026-06-26 12:28:36 -05:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* ---- Sample (preview only; CONFIG.useSample = true) ---- */
|
|
|
|
|
|
const SAMPLE = (() => {
|
|
|
|
|
|
const mk = (f, l, p, w, ls, t, pl) => ({ user: { firstName: f, lastName: l }, ITCPoints: p, wins: w, losses: ls, ties: t, placing: pl });
|
|
|
|
|
|
const kept = [
|
|
|
|
|
|
mk("Eric", "Darais", 920.7, 19, 4, 0, 453),
|
|
|
|
|
|
mk("Jordan", "Vance", 812.4, 16, 6, 1, 712),
|
|
|
|
|
|
mk("Mara", "Singh", 770.1, 15, 7, 0, 889),
|
|
|
|
|
|
mk("Devon", "Cole", 655.9, 12, 8, 2, 1340),
|
|
|
|
|
|
];
|
2026-06-26 17:34:48 -05:00
|
|
|
|
return { kept, rosterSize: 8, updated: Date.now(), live: true };
|
2026-06-26 12:28:36 -05:00
|
|
|
|
})();
|
|
|
|
|
|
|
|
|
|
|
|
/* ---- Go ---- */
|
|
|
|
|
|
$("refresh").addEventListener("click", () => load(true));
|
2026-06-26 20:13:08 -05:00
|
|
|
|
initSortHeaders();
|
2026-06-26 12:28:36 -05:00
|
|
|
|
paintCache();
|
2026-06-29 00:00:02 -05:00
|
|
|
|
loadEloData();
|
2026-06-26 12:28:36 -05:00
|
|
|
|
load(false);
|