// The Draft Board (front page): who is on the clock, this week's pool as scouting cards, the draft tracker, Best Coach standings,
// Rookie of the Week and the Best Coach pot. Every figure comes from /api/board; a missing stat says "not tracked yet".
(async function () {
FX.renderNav('/'); FX.renderFooter();
const $ = FX.$, esc = FX.esc;
const c = await FX.getConfig().catch(() => ({}));
const me = await FX.getJSON('/api/me').catch(() => ({}));
let B = null, busy = false, showAll = false;
const days = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'];
const hourLabel = h => (h % 12 || 12) + ' ' + (h < 12 ? 'AM' : 'PM');
const pol = w => w == null ? 'not tracked yet' : FX.polOf(w) + ' POL';
function hero(b) {
const d = b.draft; const cur = d && d.onClock;
const when = days[(c.draft || {}).dow == null ? 1 : c.draft.dow] + ' ' + hourLabel(b.draftHour) + ' Central';
if (d && d.status === 'live' && cur) {
$('heroKick').textContent = cur.me ? 'YOU\'RE ON THE CLOCK' : 'THE DRAFT IS LIVE';
$('heroTitle').textContent = cur.me ? 'Pick ' + cur.n + ' of Round ' + cur.round + '. Make it count.' : 'Pick ' + cur.n + ' of Round ' + cur.round + ': @' + cur.coach + ' is on the clock.';
$('heroClock').hidden = false; $('heroClock').dataset.until = cur.until;
} else if (d && d.status === 'done' && b.now < b.nextDraftAt) {
$('heroKick').textContent = 'NEXT DRAFT: ' + when.toUpperCase();
$('heroTitle').textContent = d.made ? d.made + ' players drafted this week. Get your picks started.' : 'Next draft ' + FX.when(b.nextDraftAt) + '.';
$('heroClock').hidden = false; $('heroClock').dataset.until = b.nextDraftAt;
} else {
$('heroKick').textContent = 'DRAFT DAY: ' + when.toUpperCase();
$('heroTitle').textContent = b.rounds + ' rounds. Draft order is earned.';
$('heroClock').hidden = false; $('heroClock').dataset.until = b.now < b.draftAt ? b.draftAt : b.nextDraftAt;
}
}
function clock() { const el = $('heroClock'); if (!el || el.hidden) return; const u = Number(el.dataset.until || 0); const live = B && B.draft && B.draft.status === 'live';
el.textContent = live ? 'Clock: ' + FX.left(u - Date.now() - (B.now - B.fetched)) : 'Starts in ' + FX.left(u - Date.now() - (B.now - B.fetched)); }
function scout(p, b) {
const coach = b.me && b.me.coach; const live = b.draft && b.draft.status === 'live'; const onClock = live && b.draft.onClock && b.draft.onClock.me;
const queued = b.me && (b.me.queue || []).includes(p.id);
let act = '';
if (onClock) act = '';
else if (coach && !live && b.me.credits > 0) act = '';
else if (coach) act = '';
else act = 'GET A POSITION';
const rows = [['Game plays', p.plays == null ? 'not tracked yet' : FX.n(p.plays)], ['Plays', p.game || (p.plays === 0 ? 'none yet' : p.plays == null ? 'not tracked yet' : 'none yet')]];
if (coach) rows.push(['Earned in games', pol(p.gameWei)], ['Earned surfing', p.surfWei == null && p.surfCredits != null ? FX.n(p.surfCredits) + ' ad credits' : pol(p.surfWei)]);
rows.push(['Last seen', FX.ago(p.lastSeen, b.now)], ['Came from', p.door || 'not tracked yet'], ['Wallet', p.wallet ? 'linked' : 'not yet']);
return '
The pool is empty right now. People who join the network without a sponsor show up here after their first 24 hours.
'; // tracker const d = b.draft; if (d && d.status === 'live') { $('trackTitle').textContent = 'DRAFT TRACKER: ROUND ' + (d.onClock ? d.onClock.round : ''); const rows = d.rows.slice(0, 6).reverse().map(x => 'No picks started yet this week. The first coach to get one going leads the board.
'; $('potRule').textContent = '"Started" = a pick switched on payouts or made a first purchase. The pot is 10% of every position sold this week' + (b.pot.split && b.pot.split.length ? ', shared ' + b.pot.split.join('/') + ' by the top ' + b.pot.split.length + ' coaches after the week.' : '.'); $('rookie').innerHTML = b.rookie ? FX.card(b.rookie) : 'The first pick this week to link a wallet takes it.
'; $('lastBest').innerHTML = b.lastWeekBest.length ? b.lastWeekBest.map(x => 'No results from last week yet.
'; wire(); } function wire() { document.querySelectorAll('[data-draft]').forEach(el => el.onclick = () => act('/api/draft/pick', { person: el.dataset.draft }, 'Drafted. They show on My Team now.')); document.querySelectorAll('[data-instant]').forEach(el => el.onclick = () => act('/api/my/instant', { person: el.dataset.instant }, 'Drafted. They show on My Team now.')); document.querySelectorAll('[data-queue]').forEach(el => el.onclick = async () => { const q = (B.me.queue || []).slice(); const id = el.dataset.queue; const i = q.indexOf(id); if (i >= 0) q.splice(i, 1); else q.push(id); const r = await FX.post('/api/my/queue', { ids: q }); if (r.error) return FX.status(r.error, 'err'); B.me.queue = r.queue; paint(B); }); } async function act(url, body, okMsg) { if (busy) return; busy = true; try { const r = await FX.post(url, body); if (r.error) FX.status(r.error, 'err'); else FX.status(okMsg, 'ok'); await load(); } finally { busy = false; } } async function load() { const b = await FX.getJSON('/api/board'); if (!b.error) paint(b); return b; } $('poolMore').onclick = () => { showAll = true; paint(B); }; await load(); setInterval(clock, 1000); clock(); setInterval(() => { load().catch(() => {}); }, 6000); if (me.signedIn) { const ping = () => FX.post('/api/presence', {}).catch(() => {}); ping(); setInterval(ping, 30000); } })();