Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md

Large diffs are not rendered by default.

3 changes: 3 additions & 0 deletions e63334287a3deaa3/aisles.js
Original file line number Diff line number Diff line change
Expand Up @@ -1062,6 +1062,9 @@
start: start, open: open, close: close, board: board, unboard: unboard, inviteBtn: inviteBtn, admin: admin,
of: function (u) { var A = aisleOf(u); return A ? { K: A.K, nm: A.nm, tg: A.tg, cl: A.cl, leader: A.leader, members: A.members.slice() } : null; },
get mine() { var A = mine(); return A ? A.K : ''; },
// Every Aisle shown (removed ones left out), for climb.js: [{ K, nm, tg, cl, em, members: [uid] }]; and its tag element.
list: function () { return Object.keys(aisles).map(function (K) { var A = aisles[K]; return { K: K, nm: A.nm, tg: A.tg, cl: A.cl, em: A.em, members: A.members.slice() }; }); },
tag: function (K) { return aisles[K] ? tagEl(aisles[K]) : null; },
get ready() { return ready; },
onChange: function (f) { if (typeof f === 'function') listeners.push(f); },
// Last week's contest winners (a tie: every Aisle ranked 1) from the boards' checked rows, for wallet.js's weekly
Expand Down
134 changes: 134 additions & 0 deletions e63334287a3deaa3/climb.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
/*
* Fastest climbing Aisles today (Back Room page, home page Back Room and phone page): a live panel right above
* Playing now that ranks Aisles by the Elo their members have gained today in ranked games, with green up-arrows.
*
* Data: elo.js adds every rated match's change to the player's own node rooms/elo-day/players/<uid>
* ({ n, d: New York date 'YYYY-MM-DD', gm: { <game folder>: change }, t: total today }). This file listens to
* rooms/elo-day/players (one small node per player who has ever played ranked; live, so arrows move as matches end),
* keeps only today's nodes (New York time, the same day for everyone), and adds them up per Aisle using
* BackRoomAisles.list() (members as aisles.js resolved them). An Aisle's climb is the sum of its members' totals
* (a loss counts against it); the top five Aisles that are up are shown, each with its best climber. Like every Back
* Room stat it is self-reported, for fun. Nothing is written here. Signs in only through party.js (Party.boot).
*/
(function () {
'use strict';
if (window.BackRoomClimb) return;
var PATH = 'rooms/elo-day/players', SHOW = 5;
var ES = {
'Fastest climbing Aisles today': 'Los Aisles que más suben hoy',
'Elo won in ranked games today. Win a ranked match to push your Aisle up.': 'Elo ganado hoy en partidas con rango. Gana una partida con rango para subir a tu Aisle.',
'No Aisle has climbed yet today. Win a ranked match to put yours on the board.': 'Ningún Aisle ha subido todavía hoy. Gana una partida con rango para poner el tuyo en la tabla.',
'Top climber': 'Quien más sube',
'Elo today': 'Elo hoy',
'members climbing': 'miembros subiendo'
};
function es() { try { return !!(window.BackRoomLang && BackRoomLang.get && BackRoomLang.get() === 'es'); } catch (e) { return false; } }
function T(s) { return es() && ES[s] ? ES[s] : s; }
function nyDay() {
try { return new Intl.DateTimeFormat('en-CA', { timeZone: 'America/New_York', year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date()); }
catch (e) { return new Date().toISOString().slice(0, 10); }
}
function byFilter(v) { return window.NameFilter ? window.NameFilter.clean(v) : v; }
function cleanName(s) { return byFilter(String(s == null ? '' : s).replace(/[<>\u0000-\u001f\u007f​-‏‪-‮⁦-⁩]/g, '').replace(/\s+/g, ' ').trim().slice(0, 14)) || 'Player'; }
function fmt(n) { try { return Math.round(n).toLocaleString('en-US'); } catch (e) { return String(Math.round(n)); } }

// ---------------- Styles (on top of party.js's .pty panel styles, like Playing now) ----------------
var css = document.createElement('style');
css.textContent =
'#climbing{padding-top:14px}' +
'.cl-list{list-style:none;margin:0;padding:0;display:grid;grid-template-columns:repeat(auto-fill,minmax(min(100%,300px),1fr));gap:8px}' +
'.cl-it{display:flex;align-items:center;gap:10px;background:var(--panel-2);border:1px solid var(--line);border-radius:10px;padding:8px 12px;min-width:0}' +
'.cl-n{font-family:var(--mono);font-weight:600;font-size:13px;color:var(--ink-2);width:1.6em;flex:none;text-align:center}' +
'.cl-it:first-child .cl-n{color:var(--accent)}' +
'.cl-who{display:grid;gap:2px;min-width:0;flex:1;line-height:1.25}' +
'.cl-a{display:flex;align-items:center;gap:6px;min-width:0;font-weight:600}' +
'.cl-a .cl-nm{overflow:hidden;text-overflow:ellipsis;white-space:nowrap}' +
'.cl-best{font-size:13px;color:var(--ink-2);overflow:hidden;text-overflow:ellipsis;white-space:nowrap}' +
'.cl-up{flex:none;display:flex;flex-direction:column;align-items:flex-end;line-height:1.1}' +
'.cl-up b{color:var(--up,#1fbf62);font-family:var(--mono);font-size:17px;font-weight:700;white-space:nowrap}' +
'.cl-up small{font-family:var(--mono);font-size:10px;letter-spacing:.06em;text-transform:uppercase;color:var(--ink-2)}' +
'.cl-it.cl-new b{animation:clpop .9s ease-out}' +
'@keyframes clpop{0%{transform:translateY(4px);opacity:.3}60%{transform:translateY(-2px)}100%{transform:none;opacity:1}}' +
'@media (prefers-reduced-motion:reduce){.cl-it.cl-new b{animation:none}}' +
'.cl-empty{margin:0;font-size:14px;color:var(--ink-2)}.cl-empty:empty{display:none}';
document.head.appendChild(css);

// ---------------- Panel ----------------
var sec = document.createElement('section');
sec.id = 'climbing'; sec.setAttribute('aria-label', 'Fastest climbing Aisles today'); sec.hidden = true;
sec.innerHTML = '<div class="pty cl"><div class="pty-top"><h2></h2><p class="pty-sub"></p></div><ol class="cl-list"></ol><p class="cl-empty"></p></div>';
var $h = sec.querySelector('h2'), $sub = sec.querySelector('.pty-sub'), $list = sec.querySelector('.cl-list'), $empty = sec.querySelector('.cl-empty');
// Right above Playing now (or the Party panel), so it's one of the first things on the page. Placed once.
var placed = false;
function place() {
if (placed) return; var pn = document.getElementById('playingnow'), party = document.getElementById('party'), head = document.querySelector('header');
var at = pn || party; if (!at && !head) return;
placed = true;
if (at && at.parentNode) at.parentNode.insertBefore(sec, at); else head.parentNode.insertBefore(sec, head.nextSibling);
if (party) { var mb = getComputedStyle(party).marginBottom; if (parseFloat(mb) > 0) { sec.style.paddingTop = '0'; sec.style.marginBottom = mb; } }
}

// ---------------- Data ----------------
var raw = {}, last = {};
function compute() {
var A = window.BackRoomAisles, today = nyDay(); if (!A || !A.ready || !A.list) return null;
var gain = {};
Object.keys(raw || {}).forEach(function (u) {
var v = raw[u]; if (!v || v.d !== today || !isFinite(+v.t)) return;
gain[u] = { t: Math.max(-2000, Math.min(2000, Math.round(+v.t))), n: cleanName(v.n) };
});
return A.list().map(function (a) {
var sum = 0, best = null, up = 0;
a.members.forEach(function (u) { var g = gain[u]; if (!g) return; sum += g.t; if (g.t > 0) up++; if (!best || g.t > best.t) best = g; });
return { a: a, t: sum, best: best, up: up };
}).filter(function (x) { return x.t > 0; }).sort(function (x, y) { return y.t - x.t || (x.a.nm < y.a.nm ? -1 : 1); });
}
function draw() {
var rows = compute(); if (!rows) return;
place();
$h.textContent = T('Fastest climbing Aisles today');
$sub.textContent = T('Elo won in ranked games today. Win a ranked match to push your Aisle up.');
var A = window.BackRoomAisles, any = A.list().length > 0;
sec.hidden = !any;
$list.textContent = '';
$empty.textContent = rows.length ? '' : T('No Aisle has climbed yet today. Win a ranked match to put yours on the board.');
var now = {};
rows.slice(0, SHOW).forEach(function (x, i) {
var li = document.createElement('li'); li.className = 'cl-it';
if (last[x.a.K] !== undefined && last[x.a.K] < x.t) li.classList.add('cl-new');
now[x.a.K] = x.t;
var n = document.createElement('span'); n.className = 'cl-n'; n.textContent = (i + 1);
var who = document.createElement('div'); who.className = 'cl-who';
var an = document.createElement('div'); an.className = 'cl-a';
var tg = A.tag ? A.tag(x.a.K) : null; if (tg) an.appendChild(tg);
var nm = document.createElement('span'); nm.className = 'cl-nm'; nm.textContent = x.a.nm; an.appendChild(nm);
who.appendChild(an);
if (x.best && x.best.t > 0) { var b = document.createElement('div'); b.className = 'cl-best'; b.textContent = T('Top climber') + ': ' + x.best.n + ' +' + fmt(x.best.t) + (x.up > 1 ? ' · ' + x.up + ' ' + T('members climbing') : ''); who.appendChild(b); }
var up = document.createElement('div'); up.className = 'cl-up';
var v = document.createElement('b'); v.textContent = '▲ +' + fmt(x.t); v.setAttribute('aria-label', '+' + fmt(x.t) + ' Elo today');
var sm = document.createElement('small'); sm.textContent = T('Elo today');
up.append(v, sm);
li.append(n, who, up); $list.appendChild(li);
});
last = now;
}

function start() {
var n = 0;
(function wait() {
if (window.Party && Party.boot && window.BackRoomAisles) {
Party.boot().then(function (b) {
b.db.ref(PATH).on('value', function (s) { raw = s.val() || {}; draw(); });
}).catch(function () {});
if (BackRoomAisles.onChange) BackRoomAisles.onChange(draw);
document.addEventListener('backroom:lang', draw);
setInterval(draw, 60000); // a new day starts the board afresh
return;
}
if (++n < 300) setTimeout(wait, 200);
})();
}
window.BackRoomClimb = { compute: compute, draw: draw, nyDay: nyDay };
if (navigator.webdriver) window.__climb = { set: function (r) { raw = r || {}; draw(); } }; // tests only
start();
})();
25 changes: 24 additions & 1 deletion e63334287a3deaa3/elo.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,29 @@
} catch (e) {}
}

// ---------------- Today's climb ----------------
// Every rated match adds its change to rooms/elo-day/players/<uid> ({ d: the New York date, gm: { <folder>: change
// today }, t: the total }), started afresh on a new day. climb.js adds these up per Aisle for the Back Room's
// "Fastest climbing Aisles today". One small node per player, so the Back Room reads one place instead of every game's.
function nyDay() {
try { return new Intl.DateTimeFormat('en-CA', { timeZone: 'America/New_York', year: 'numeric', month: '2-digit', day: '2-digit' }).format(new Date()); }
catch (e) { return new Date().toISOString().slice(0, 10); }
}
function day(delta) {
var c = conn(); if (!c || !isFinite(delta)) return;
try {
var ref = c.db.ref('rooms/elo-day/players/' + c.uid);
timeout(ref.once('value'), 5000).then(function (s) {
if (!s) return; // couldn't read: don't overwrite today's total with just this match
var v = s.val() || {}, d = nyDay(), gm = {};
if (v.d === d && v.gm && typeof v.gm === 'object') Object.keys(v.gm).forEach(function (k) { if (/^[a-z0-9-]{1,32}$/.test(k) && isFinite(+v.gm[k])) gm[k] = Math.round(+v.gm[k]); });
gm[GAME] = (gm[GAME] || 0) + Math.round(delta);
var t = 0; Object.keys(gm).forEach(function (k) { t += gm[k]; });
return ref.set({ n: myName(), c: '#8b95b8', x: 0, z: 0, h: 0, ts: c.F.database.ServerValue.TIMESTAMP, d: d, gm: gm, t: t });
}).catch(function () {});
} catch (e) {}
}

// ---------------- Rank-up share card ----------------
// After a rated match, flex.js (loaded only now) checks for a new tier or a top-100 place and offers a share card.
function flex(res) {
Expand Down Expand Up @@ -164,7 +187,7 @@
var res = { game: GAME, before: before, after: Math.round(rank.r), delta: Math.round(rank.r) - before, humans: humans.length, w: w };
show(res.before, res.after, res.delta);
try { document.dispatchEvent(new CustomEvent('backroom:elo', { detail: res })); } catch (e) {}
flex(res);
flex(res); day(res.delta);
busy = false; return res;
}).catch(function () { busy = false; return null; });
} catch (e) { busy = false; return Promise.resolve(null); }
Expand Down
1 change: 1 addition & 0 deletions e63334287a3deaa3/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -1220,6 +1220,7 @@ <h3>Flood Crew</h3>
<script src="/e63334287a3deaa3/aisles.js" defer></script>
<script src="/e63334287a3deaa3/avismiles.js" defer></script>
<script src="/e63334287a3deaa3/playingnow.js" defer></script>
<script src="/e63334287a3deaa3/climb.js" defer></script> <!-- Fastest climbing Aisles today (climb.js) -->
<script src="/e63334287a3deaa3/door.js" defer></script>
<script src="/e63334287a3deaa3/seasons.js" defer></script>
<script src="/e63334287a3deaa3/events.js" defer></script>
Expand Down
1 change: 1 addition & 0 deletions e63334287a3deaa3/m/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -395,6 +395,7 @@ <h1><span data-door>ASC</span>oding <span>games</span></h1>
// Avis miles (avismiles.js): the claim dialog, opened from the Online panel or #avis-miles.
var avm=document.createElement('script');avm.src=B+'avismiles.js';document.body.appendChild(avm);
var pn=document.createElement('script');pn.src=B+'playingnow.js';document.body.appendChild(pn);
var cl=document.createElement('script');cl.src=B+'climb.js';document.body.appendChild(cl); // Fastest climbing Aisles today (climb.js)
// Your school (school.js): fills in the [data-school] box under the header.
var sk=document.createElement('script');sk.src=B+'school.js';document.body.appendChild(sk);

Expand Down
18 changes: 18 additions & 0 deletions e63334287a3deaa3/news/aisles-climbing-today.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"kind": "feature",
"title": "Fastest climbing Aisles today",
"tags": ["Aisles", "Elo"],
"items": [
"A new board at the top of the Back Room shows which Aisles are climbing fastest today, with live green arrows.",
"It adds up the Elo every member wins in ranked games today, and names each Aisle's top climber.",
"It starts fresh every day, so any Aisle can top it."
],
"es": {
"Fastest climbing Aisles today": "Los Aisles que más suben hoy",
"Aisles": "Aisles",
"Elo": "Elo",
"A new board at the top of the Back Room shows which Aisles are climbing fastest today, with live green arrows.": "Una nueva tabla arriba del Back Room muestra qué Aisles están subiendo más rápido hoy, con flechas verdes en vivo.",
"It adds up the Elo every member wins in ranked games today, and names each Aisle's top climber.": "Suma el Elo que cada miembro gana hoy en partidas con rango y nombra a quien más sube en cada Aisle.",
"It starts fresh every day, so any Aisle can top it.": "Empieza de cero cada día, así que cualquier Aisle puede llegar arriba."
}
}
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,7 @@ <h3>Productivity</h3>
if(/^xj-[0-9a-z]{16}$/.test(room)){try{sessionStorage.setItem('aisle:inv',room.slice(3))}catch(e){}room=''}
var ai=document.createElement('script');ai.src=dir+'aisles.js';document.body.appendChild(ai);
var pn=document.createElement('script');pn.src=dir+'playingnow.js';document.body.appendChild(pn); // Playing now: public parties' games (playingnow.js)
var cb=document.createElement('script');cb.src=dir+'climb.js';document.body.appendChild(cb); // Fastest climbing Aisles today (climb.js)
// The seasonal look (seasons.js) is only for the Back Room, so the home page loads it once the Back Room is open.
var se=document.createElement('script');se.src=dir+'seasons.js';document.body.appendChild(se);
// The Turkey Week switch (events.js) is a button in the Back Room's header, which was copied in above; this fills it in.
Expand Down
Loading