@ywkrlerche/richardwho 1.0.43 → 1.0.44

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/app.js CHANGED
@@ -293,63 +293,182 @@
293
293
  return `<svg class="web ${flip ? "right" : "left"}" viewBox="0 0 270 270"><path d="${d}"/></svg>`;
294
294
  }
295
295
  // ---------- Themes (Settings → Theme): Holiday (the theme follows the calendar, Black between holidays), Black or White ----------
296
- // The holiday dates live in index.html's head script (window.rugHoliday) so the right look shows before this file loads.
297
- // The smaller holidays share one look (.fest): their colors live in style.css, the falling things and props here.
296
+ // The holiday dates live in index.html's head script (window.rugHoliday / rugHolidayDay) so the right look shows
297
+ // before this file loads. Halloween and Christmas have their own scenery; the rest share one look (.fest): colors
298
+ // in style.css, and here the falling things, ground props, a drawn scene, bunting and fireworks.
299
+ const seeded = (seed) => () => ((seed = (seed * 1664525 + 1013904223) >>> 0) / 4294967296); // repeatable "random" for drawings
300
+ const HILLS = `<path class="s-hill" d="M0 200C200 170 420 190 640 180S1100 165 1300 182 1520 186 1600 176V240H0Z"/>`;
301
+ // Scenes are drawn in a 1600 x 240 box whose bottom edge is the bottom of the page
302
+ const SCENES = {
303
+ skyline() {
304
+ const r = seeded(7);
305
+ let x = 0, towers = "", windows = "";
306
+ while (x < 1600) {
307
+ const w = 44 + r() * 60, h = 50 + r() * 120, y = 240 - h;
308
+ towers += `<rect x="${x.toFixed(0)}" y="${y.toFixed(0)}" width="${(w + 1).toFixed(0)}" height="${h.toFixed(0)}"/>`;
309
+ for (let wy = y + 10; wy < 226; wy += 16) for (let wx = x + 8; wx < x + w - 10; wx += 14) if (r() < .3) windows += `<rect x="${wx.toFixed(0)}" y="${wy.toFixed(0)}" width="6" height="8"/>`;
310
+ x += w;
311
+ }
312
+ return `<g class="s-dark">${towers}</g><g class="s-win">${windows}</g>`;
313
+ },
314
+ hearts() {
315
+ const heart = (x, y, s, c, delay) => `<g transform="translate(${x} ${y}) scale(${s})"><g class="s-float" style="animation-delay:${delay}s">` +
316
+ `<path d="M0 32q7 34-3 78" stroke="rgba(255,255,255,.28)" fill="none" stroke-width="1.2"/><path d="M0 9C-12-8-32 4 0 32 32 4 12-8 0 9Z" fill="${c}"/></g></g>`;
317
+ return HILLS + heart(560, 70, 1.5, "#fb7185", 0) + heart(690, 96, 1.1, "#f472b6", -1.2) + heart(1010, 60, 1.7, "#e11d48", -2.1) +
318
+ heart(1130, 104, 1, "#fda4af", -.6) + heart(1400, 80, 1.3, "#f472b6", -1.7);
319
+ },
320
+ rainbow() {
321
+ const bands = ["#ef4444", "#f97316", "#facc15", "#22c55e", "#3b82f6", "#8b5cf6"];
322
+ return `<g fill="none" stroke-width="11" opacity=".5">${bands.map((c, i) => `<circle cx="1120" cy="262" r="${236 - i * 11}" stroke="${c}"/>`).join("")}</g>` +
323
+ `<path fill="#0f3320" d="M0 190C260 150 520 196 800 178S1300 150 1600 184V240H0Z"/>` + HILLS;
324
+ },
325
+ eggs() {
326
+ const egg = (x, y, c1, c2, tilt) => `<g transform="translate(${x} ${y}) rotate(${tilt})"><ellipse rx="15" ry="20" fill="${c1}"/>` +
327
+ `<path d="M-14-4q7-7 14 0t14 0" stroke="${c2}" stroke-width="4" fill="none"/><path d="M-13 8q6.5 6 13 0t13 0" stroke="${c2}" stroke-width="3" fill="none"/></g>`;
328
+ return `<circle cx="1380" cy="64" r="58" fill="#fde68a" opacity=".12"/><circle cx="1380" cy="64" r="34" fill="#fde68a" opacity=".85"/>` +
329
+ `<path fill="#1d3a2a" d="M0 186C240 150 470 190 760 170S1280 146 1600 178V240H0Z"/><path fill="#234732" d="M0 206C200 184 420 204 640 196S1100 182 1300 198 1520 200 1600 192V240H0Z"/>` +
330
+ egg(540, 196, "#c4b5fd", "#f9a8d4", -8) + egg(620, 204, "#86efac", "#fde68a", 10) + egg(860, 194, "#f9a8d4", "#c4b5fd", 4) +
331
+ egg(1020, 200, "#fde68a", "#86efac", -12) + egg(1200, 192, "#93c5fd", "#f9a8d4", 8);
332
+ },
333
+ harvest() {
334
+ const tree = (x, s) => `<g transform="translate(${x} 0) scale(${s} 1)"><path d="M0 204V120M0 140l-50-40M0 125l45-45M-30 116l-26 4M25 96l24-6M0 160l40-12" stroke-width="9" stroke-linecap="round" fill="none"/></g>`;
335
+ const pumpkin = (x, y, r) => `<g transform="translate(${x} ${y})"><path d="M0 ${-r}v-9" stroke="#3f6212" stroke-width="5" stroke-linecap="round"/>` +
336
+ `<ellipse rx="${r * 1.15}" ry="${r}" fill="#ea580c"/><ellipse rx="${r * .5}" ry="${r}" fill="#f97316"/></g>`;
337
+ return `<circle cx="1080" cy="214" r="96" fill="#f59e0b" opacity=".16"/><circle cx="1080" cy="214" r="62" fill="#f59e0b" opacity=".2"/>` + HILLS +
338
+ `<g class="s-dark">${tree(520, 1)}${tree(1460, -1.1)}</g>` +
339
+ `<rect x="850" y="176" width="64" height="30" rx="5" fill="#b8892f"/><path d="M866 176v30M882 176v30M898 176v30" stroke="#8a6420" stroke-width="2"/>` +
340
+ pumpkin(700, 196, 17) + pumpkin(746, 202, 12) + pumpkin(990, 198, 15);
341
+ },
342
+ football() {
343
+ const lines = Array.from({ length: 9 }, (_, i) => `<path d="M${180 + i * 155} 240L${420 + i * 95} 168"/>`).join("");
344
+ const light = (x) => `<path d="M${x} 240V52" stroke="#1f2937" stroke-width="7"/><rect x="${x - 34}" y="30" width="68" height="26" rx="4" fill="#111827"/>` +
345
+ Array.from({ length: 4 }, (_, i) => `<circle cx="${x - 24 + i * 16}" cy="43" r="5" fill="#fef9c3"/>`).join("") + `<circle cx="${x}" cy="43" r="60" fill="#fef9c3" opacity=".07"/>`;
346
+ return light(140) + light(1470) + `<path fill="#14532d" d="M0 240L330 168H1270L1600 240Z"/><g stroke="rgba(255,255,255,.35)" stroke-width="2">${lines}</g>` +
347
+ `<path d="M1180 172V112M1136 112H1224M1136 112V52M1224 112V52" stroke="#facc15" stroke-width="6" stroke-linecap="round" fill="none"/>`;
348
+ },
349
+ beach() {
350
+ const palm = (x, s) => `<g transform="translate(${x} 0) scale(${s} 1)" class="s-dark"><path d="M0 214C6 170 2 130 18 92" stroke-width="10" stroke-linecap="round" fill="none"/>` +
351
+ `<path stroke="none" d="M18 92C-8 72-40 78-58 98-34 90-10 92 18 92ZM18 92C2 62-22 50-48 54-24 62-4 74 18 92ZM18 92C22 60 44 44 70 46 48 56 30 72 18 92ZM18 92C44 76 76 80 92 102 68 92 44 92 18 92ZM18 92C40 96 58 112 62 134 48 116 34 104 18 92Z"/></g>`;
352
+ return `<circle cx="1160" cy="176" r="74" fill="#fbbf24" opacity=".9"/><circle cx="1160" cy="176" r="110" fill="#fbbf24" opacity=".12"/>` +
353
+ `<path fill="#0e3a5c" d="M0 178q40-10 80 0t80 0 80 0 80 0 80 0 80 0 80 0 80 0 80 0 80 0 80 0 80 0 80 0 80 0 80 0 80 0 80 0 80 0 80 0 80 0V240H0Z"/>` +
354
+ `<path fill="#0b2c47" d="M0 200q50-9 100 0t100 0 100 0 100 0 100 0 100 0 100 0 100 0 100 0 100 0 100 0 100 0 100 0 100 0 100 0 100 0V240H0Z"/>` +
355
+ `<path fill="#3a2f1c" d="M0 214C140 196 300 204 470 226L520 240H0ZM1600 208C1480 196 1340 206 1220 232L1190 240H1600Z"/>` + palm(250, 1) + palm(1440, -1.15);
356
+ },
357
+ school() {
358
+ const windows = [690, 740, 860, 910].map((x) => `<rect x="${x}" y="150" width="26" height="30" rx="2"/>`).join("");
359
+ return HILLS + `<g class="s-dark"><rect x="660" y="128" width="300" height="80"/><path d="M640 130L810 76 980 130Z"/><rect x="786" y="44" width="48" height="50"/><path d="M776 46L810 22 844 46Z"/><path d="M1010 208V96" stroke-width="4"/></g>` +
360
+ `<g class="s-win">${windows}<circle cx="810" cy="66" r="9"/></g><rect x="792" y="160" width="36" height="48" rx="3" fill="#7c2d12"/><path d="M1012 98h44l-10 12 10 12h-44Z" fill="#f87171"/>` +
361
+ `<g transform="translate(1150 150)"><rect width="190" height="54" rx="10" fill="#facc15"/><rect x="150" y="10" width="32" height="22" rx="3" fill="#1e293b"/>` +
362
+ [14, 46, 78, 110].map((x) => `<rect x="${x}" y="10" width="24" height="20" rx="3" fill="#1e293b"/>`).join("") +
363
+ `<rect y="36" width="190" height="5" fill="#111827"/><circle cx="42" cy="56" r="13" fill="#111827"/><circle cx="148" cy="56" r="13" fill="#111827"/><circle cx="42" cy="56" r="5" fill="#9ca3af"/><circle cx="148" cy="56" r="5" fill="#9ca3af"/></g>`;
364
+ },
365
+ };
366
+ // items: what falls (up: floats upward instead). ground: emoji along the bottom. flags: bunting colors.
367
+ // fw: firework colors; they go off all holiday with fwAlways, otherwise only on the day itself.
368
+ const RWB = ["#ef4444", "#f8fafc", "#3b82f6"];
298
369
  const FESTS = {
299
- newyear: { color: "#0a0d1f", items: ["✨", "🎉", "🎊", "⭐"], ground: ["🥂", "🎆", "🍾", "🎇"], count: 70 },
300
- valentines: { color: "#1f0a14", items: ["💖", "💕", "❤️", "💗"], ground: ["🌹", "💝", "🧸", "💌"], count: 65 },
301
- stpatricks: { color: "#06170d", items: ["☘️", "🍀", "🪙"], ground: ["🌈", "💰", "🍀", "🎩"], count: 65 },
302
- easter: { color: "#160f24", items: ["🌸", "🌷", "🦋"], ground: ["🐣", "🧺", "🐰", "🥚"], count: 60 },
303
- july4: { color: "#070b1f", items: ["⭐", "✨", "🎆"], ground: ["🗽", "🎆", "🌭", "🎇"], count: 65 },
304
- thanksgiving: { color: "#1a0f06", items: ["🍂", "🍁", "🍃"], ground: ["🦃", "🥧", "🌽", "🍂"], count: 65 },
370
+ newyear: { color: "#0a0d1f", items: ["✨", "🎉", "🎊", "⭐"], ground: ["🥂", "🎆", "🍾", "🎇"], count: 60, scene: SCENES.skyline, flags: ["#facc15", "#f8fafc", "#818cf8"], fw: ["#facc15", "#f8fafc", "#818cf8", "#f472b6"], fwAlways: true },
371
+ valentines: { color: "#1f0a14", items: ["💖", "💕", "❤️", "💗"], ground: ["🌹", "💝", "🧸", "💌"], count: 65, scene: SCENES.hearts, flags: ["#f472b6", "#fb7185", "#ffe4ef"] },
372
+ stpatricks: { color: "#06170d", items: ["☘️", "🍀", "🪙"], ground: ["💰", "🎩", "🍀", "🪙"], count: 65, scene: SCENES.rainbow, flags: ["#22c55e", "#facc15", "#f8fafc"] },
373
+ easter: { color: "#160f24", items: ["🌸", "🌷", "🦋"], ground: ["🐰", "🧺", "🐣", "🌷"], count: 60, scene: SCENES.eggs, flags: ["#c4b5fd", "#f9a8d4", "#86efac", "#fde68a"] },
374
+ july4: { color: "#070b1f", items: ["⭐", "✨"], ground: ["🗽", "🌭", "🧨", "🎇"], count: 45, scene: SCENES.skyline, flags: RWB, fw: RWB, fwAlways: true },
375
+ thanksgiving: { color: "#1a0f06", items: ["🍂", "🍁", "🍃"], ground: ["🦃", "🥧", "🌽", "🍎"], count: 65, scene: SCENES.harvest },
376
+ superbowl: { color: "#07140c", items: ["🏈", "⭐", "🎉"], ground: ["🏆", "🏈", "🍕", "📣"], count: 45, scene: SCENES.football, flags: ["#fbbf24", "#f8fafc", "#4ade80"], fw: ["#fbbf24", "#f8fafc", "#4ade80"] },
377
+ aprilfools: { color: "#14101f", items: ["🤡", "🃏", "🙃", "🎈"], ground: ["🎩", "🐇", "🎪", "🃏"], count: 45, up: true, flags: ["#ef4444", "#facc15", "#22c55e", "#3b82f6", "#a78bfa"] },
378
+ summer: { color: "#0b1a2b", items: ["🫧", "✨"], ground: ["🏖️", "🍉", "🏄", "🍦"], count: 34, up: true, scene: SCENES.beach },
379
+ backtoschool: { color: "#101426", items: ["✏️", "📚", "🍎", "📐"], ground: ["🎒", "📓", "🍎", "🖍️"], count: 40, scene: SCENES.school, flags: ["#facc15", "#f87171", "#60a5fa"] },
305
380
  };
306
381
  const HOLIDAYS = ["halloween", "christmas", ...Object.keys(FESTS)];
307
382
  const SPOOKY_FALL = { items: ["🍂", "🍁", "🍬", "🦇"], count: 50 };
383
+ // [emoji, "N days until …", greeting on the day]; seasons without one big day just get a note
384
+ const HOLIDAY_DAYS = {
385
+ newyear: ["🎉", "New Year's Day", ""], valentines: ["💘", "Valentine's Day", "Happy Valentine's Day!"],
386
+ stpatricks: ["☘️", "St. Patrick's Day", "Happy St. Patrick's Day!"], easter: ["🐣", "Easter", "Happy Easter!"],
387
+ july4: ["🎆", "the Fourth of July", "Happy Fourth of July!"], halloween: ["🎃", "Halloween", "Happy Halloween!"],
388
+ thanksgiving: ["🦃", "Thanksgiving", "Happy Thanksgiving!"], christmas: ["🎄", "Christmas", "Merry Christmas!"],
389
+ superbowl: ["🏈", "the Super Bowl", "It's Super Bowl Sunday!"], aprilfools: ["🤡", "April Fools' Day", "Happy April Fools' Day! Nothing is broken. Probably."],
390
+ };
391
+ const SEASON_NOTES = { summer: "☀️ Summer break. Enjoy it!", backtoschool: "✏️ Welcome back to school!" };
308
392
  const THEMES = ["auto", "black", "white"];
309
393
  function resolveTheme(t) {
310
394
  return t === "black" || t === "white" ? t : (window.rugHoliday && window.rugHoliday()) || "black";
311
395
  }
312
- let shownTheme = null;
396
+ // days until this theme's big day (0 = today, negative = it has passed, null = it has none)
397
+ function daysToHoliday(t) {
398
+ const day = HOLIDAY_DAYS[t] && window.rugHolidayDay && window.rugHolidayDay(t);
399
+ if (!day) return null;
400
+ const n = new Date();
401
+ return Math.round((day - new Date(n.getFullYear(), n.getMonth(), n.getDate()).getTime()) / 864e5);
402
+ }
403
+ const themeKey = (t) => `${t}:${daysToHoliday(t)}`;
404
+ let shownTheme = null, shownKey = "";
313
405
  function applySiteTheme(choice) {
314
406
  const t = resolveTheme(choice);
315
407
  shownTheme = t;
408
+ shownKey = themeKey(t);
316
409
  const root = document.documentElement;
317
410
  root.dataset.theme = t === "white" ? "light" : "dark";
318
411
  for (const h of HOLIDAYS) root.classList.toggle(h, t === h);
319
412
  root.classList.toggle("fest", !!FESTS[t]);
413
+ root.classList.toggle("holiday", HOLIDAYS.includes(t)); // shared touches on every page (style.css)
320
414
  $("theme-color").content = { white: "#f6f6f8", halloween: "#110820", christmas: "#0b1424" }[t] || FESTS[t]?.color || "#000000";
321
415
  if (t === "halloween" && !document.querySelector(".spooky")) buildHalloween(); // scenery is only drawn once it's needed
322
416
  if (t === "christmas" && !document.querySelector(".xmas")) buildChristmas();
323
417
  if (FESTS[t]) buildFest(t);
324
418
  fallers.set(t);
419
+ renderHolidayBanner();
420
+ }
421
+ // Under the home page search: "12 days until Christmas", a greeting on the day, a countdown on New Year's Eve
422
+ function renderHolidayBanner() {
423
+ const t = shownTheme, info = HOLIDAY_DAYS[t], left = daysToHoliday(t);
424
+ let text = SEASON_NOTES[t] || "";
425
+ if (info && left === 0) text = t === "newyear" ? `🎉 Happy New Year ${new Date().getFullYear()}!` : `${info[0]} ${info[2]}`;
426
+ else if (info && left === 1 && t === "newyear") {
427
+ const ms = window.rugHolidayDay(t) - Date.now(), h = Math.floor(ms / 3600e3), m = Math.ceil((ms % 3600e3) / 60e3);
428
+ text = `🎉 New Year in ${h ? `${h}h ` : ""}${m}m`;
429
+ } else if (info && left > 0) text = `${info[0]} ${left} day${left === 1 ? "" : "s"} until ${info[1]}`;
430
+ $("holiday-banner").textContent = text;
431
+ $("holiday-banner").hidden = !text;
432
+ }
433
+ // a tab left open still switches when a holiday starts or ends or its big day arrives, and the countdown keeps up
434
+ setInterval(() => { if (themeKey(resolveTheme(settings.theme)) !== shownKey) applySiteTheme(settings.theme); else renderHolidayBanner(); }, 60e3);
435
+ function bunting(colors) {
436
+ const n = 30;
437
+ return `<div class="bunting"><svg viewBox="0 0 100 10" preserveAspectRatio="none"><path d="M0 2Q8 9 16 3T32 3 48 3 64 3 80 3 100 3"/></svg>` +
438
+ Array.from({ length: n }, (_, i) => `<i style="left:${(i + .5) * (100 / n)}%;top:${9 + Math.sin(i * 1.3) * 5}px;--c:${colors[i % colors.length]};animation-delay:${(i % 6) * -.5}s"></i>`).join("") + `</div>`;
325
439
  }
326
- // a tab left open overnight still switches when a holiday starts or ends
327
- setInterval(() => { if (resolveTheme(settings.theme) !== shownTheme) applySiteTheme(settings.theme); }, 10 * 60e3);
328
440
  function buildFest(t) {
329
441
  const old = document.querySelector(".festive");
330
442
  if (old?.dataset.fest === t) return;
331
443
  old?.remove();
444
+ const f = FESTS[t];
332
445
  const spots = ["right:4vw", "right:calc(4vw + 78px)", "right:calc(4vw + 150px)", "right:calc(4vw + 206px)"];
333
446
  $("view-home").insertAdjacentHTML("afterbegin", `<div class="festive" data-fest="${t}" aria-hidden="true">
334
- <svg class="festive-hills" viewBox="0 0 1600 240" preserveAspectRatio="xMidYMax slice"><path d="M0 200C200 170 420 190 640 180S1100 165 1300 182 1520 186 1600 176V240H0Z"/></svg>
335
- ${FESTS[t].ground.map((e, i) => `<span class="festive-prop" style="${spots[i]};--s:${i % 2 ? 40 : 54}px;animation-delay:${i * -1.3}s">${e}</span>`).join("")}
447
+ ${f.flags ? bunting(f.flags) : ""}
448
+ <svg class="festive-scene" viewBox="0 0 1600 240" preserveAspectRatio="xMidYMax slice">${f.scene ? f.scene() : HILLS}</svg>
449
+ ${f.ground.map((e, i) => `<span class="festive-prop" style="${spots[i]};--s:${i % 2 ? 40 : 54}px;animation-delay:${i * -1.3}s">${e}</span>`).join("")}
336
450
  </div>`);
337
451
  }
338
452
 
339
- // Falling snow (Christmas) or hearts, leaves, clovers… (the other holidays) on the home page.
340
- // The pointer pushes them aside; clicking empty space (or the snowman) bursts out more.
453
+ // Falling snow (Christmas) or hearts, leaves, clovers… (the other holidays) on the home page, plus fireworks.
454
+ // The pointer pushes them aside; clicking empty space bursts out more (and sets off a firework when there are any).
341
455
  const fallers = {
342
456
  canvas: null, ctx: null, list: [], kind: null, items: [], sprites: {}, target: 0, raf: 0, last: 0, measured: 0,
343
- w: 0, h: 0, ox: 0, oy: 0, px: -1e4, py: -1e4,
457
+ w: 0, h: 0, ox: 0, oy: 0, px: -1e4, py: -1e4, dir: 1, fw: null, fwRate: 0, sparks: [],
344
458
  still: matchMedia("(prefers-reduced-motion: reduce)").matches,
345
459
  set(theme) {
346
460
  const fall = theme === "halloween" ? SPOOKY_FALL : FESTS[theme];
347
461
  this.kind = theme === "christmas" ? "snow" : fall ? "emoji" : null;
348
462
  if (!this.kind) { cancelAnimationFrame(this.raf); this.raf = 0; if (this.canvas) this.canvas.hidden = true; return; }
349
463
  if (!this.canvas) this.init();
464
+ const big = daysToHoliday(theme) === 0; // the day itself: more of everything
350
465
  this.items = fall?.items || [];
466
+ this.dir = fall?.up ? -1 : 1;
467
+ this.fw = fall?.fw && (fall.fwAlways || big) ? fall.fw : null;
468
+ this.fwRate = big ? 1.1 : .3; // fireworks a second
469
+ this.sparks = [];
351
470
  const small = innerWidth < 720;
352
- this.target = this.kind === "snow" ? (small ? 150 : 320) : Math.round(fall.count * (small ? .5 : 1));
471
+ this.target = Math.round((this.kind === "snow" ? (small ? 150 : 320) : fall.count * (small ? .5 : 1)) * (big ? 1.6 : 1));
353
472
  this.list = Array.from({ length: this.target }, () => this.make(true));
354
473
  this.canvas.hidden = false;
355
474
  this.start();
@@ -367,6 +486,7 @@
367
486
  if (!this.kind || $("view-home").hidden) return;
368
487
  if (e.target.closest("a, button, input, select, textarea, label, [role=button], .rail, .quote-strip, .home-search")) return;
369
488
  this.burst(e.clientX, e.clientY, 18);
489
+ if (this.fw) this.firework(e.clientX - this.ox, e.clientY - this.oy);
370
490
  });
371
491
  },
372
492
  resize() {
@@ -381,7 +501,7 @@
381
501
  make(spread, x, y) {
382
502
  const snow = this.kind === "snow";
383
503
  return {
384
- x: x ?? Math.random() * this.w, y: y ?? (spread ? Math.random() * this.h : -30), vx: 0, vy: 0,
504
+ x: x ?? Math.random() * this.w, y: y ?? (spread ? Math.random() * this.h : this.dir < 0 ? this.h + 30 : -30), vx: 0, vy: 0,
385
505
  fall: snow ? .35 + Math.random() * .8 : .45 + Math.random() * .6,
386
506
  size: snow ? 1.2 + Math.random() * 2.8 : 16 + Math.random() * 14,
387
507
  phase: Math.random() * 6.28, sway: .4 + Math.random() * .8, rot: Math.random() * 6.28, spin: (Math.random() - .5) * .03,
@@ -397,6 +517,14 @@
397
517
  }
398
518
  this.start();
399
519
  },
520
+ firework(x, y) {
521
+ if (this.sparks.length > 700) return;
522
+ const c = this.fw[Math.floor(Math.random() * this.fw.length)], c2 = this.fw[Math.floor(Math.random() * this.fw.length)];
523
+ for (let i = 0; i < 54; i++) {
524
+ const a = Math.random() * Math.PI * 2, s = 1.2 + Math.random() * 3.6;
525
+ this.sparks.push({ x, y, vx: Math.cos(a) * s, vy: Math.sin(a) * s, life: .7 + Math.random() * .4, c: i % 3 ? c : c2 });
526
+ }
527
+ },
400
528
  // each emoji is drawn once onto a small canvas and then stamped, much cheaper than drawing text every frame
401
529
  sprite(ch) {
402
530
  if (!this.sprites[ch]) {
@@ -423,6 +551,20 @@
423
551
  if (t - this.measured > 1000) { this.measured = t; this.resize(); } // the side bar can slide in or out
424
552
  const ctx = this.ctx, snow = this.kind === "snow", R = 110, damp = Math.pow(.95, dt);
425
553
  ctx.clearRect(0, 0, this.w, this.h);
554
+ if (this.fw && !this.still && Math.random() < this.fwRate * dt / 60) this.firework(this.w * (.1 + Math.random() * .8), this.h * (.12 + Math.random() * .36));
555
+ if (this.sparks.length) {
556
+ const slow = Math.pow(.97, dt);
557
+ for (let i = this.sparks.length - 1; i >= 0; i--) {
558
+ const s = this.sparks[i];
559
+ s.life -= .012 * dt;
560
+ if (s.life <= 0) { this.sparks.splice(i, 1); continue; }
561
+ s.vx *= slow; s.vy = s.vy * slow + .035 * dt; s.x += s.vx * dt; s.y += s.vy * dt;
562
+ ctx.globalAlpha = Math.min(1, s.life * 1.6);
563
+ ctx.fillStyle = s.c;
564
+ ctx.fillRect(s.x - 1.5, s.y - 1.5, 3, 3);
565
+ }
566
+ ctx.globalAlpha = 1;
567
+ }
426
568
  if (snow) { ctx.fillStyle = "rgba(255, 255, 255, .85)"; ctx.beginPath(); } else ctx.globalAlpha = .85;
427
569
  for (let i = this.list.length - 1; i >= 0; i--) {
428
570
  const p = this.list[i];
@@ -430,8 +572,8 @@
430
572
  if (d2 < R * R) { const d = Math.sqrt(d2) || 1, f = (1 - d / R) * 1.6 * dt; p.vx += dx / d * f; p.vy += dy / d * f; }
431
573
  p.vx *= damp; p.vy *= damp; p.phase += .02 * dt; p.rot += p.spin * dt;
432
574
  p.x += (p.vx + Math.sin(p.phase) * p.sway * .5) * dt;
433
- p.y += (p.vy + p.fall) * dt;
434
- if (p.y > this.h + 30 || p.x < -40 || p.x > this.w + 40) {
575
+ p.y += (p.vy + p.fall * this.dir) * dt;
576
+ if (p.y > this.h + 40 || p.y < -40 || p.x < -40 || p.x > this.w + 40) {
435
577
  if (p.extra) { this.list.splice(i, 1); continue; }
436
578
  Object.assign(p, this.make(false));
437
579
  }
@@ -784,15 +926,20 @@
784
926
  function play(id) { location.hash = `#play/${encodeURIComponent(id)}`; }
785
927
  // instant: switch right away, no slide (used when typing on the home search moves you to Games,
786
928
  // so the Games search box can take focus before the next key arrives)
929
+ // This page's own address. Inside the .svg version a <base> tag points relative links at the package folder,
930
+ // so a bare "#games" would turn the address into that folder: always build addresses from this instead.
931
+ const PAGE_URL = location.pathname + location.search;
787
932
  function go(view, { instant = false } = {}) {
788
933
  const target = view === "home" ? "" : `#${view}`;
789
- if (location.hash !== target) history.pushState(null, "", target || location.pathname + location.search);
934
+ if (location.hash !== target) history.pushState(null, "", PAGE_URL + target);
790
935
  const after = () => { if (view !== "recent") window.scrollTo(0, 0); };
791
936
  if (instant) { routeNow(); after(); } else route(after);
792
937
  }
793
938
  function goBack() {
794
- if (location.hash.startsWith("#play/")) history.length > 1 ? history.back() : (location.hash = "#games");
795
- else if (location.hash) go("home");
939
+ if (!location.hash.startsWith("#play/")) { if (location.hash) go("home"); return; }
940
+ // framed (.svg version): the frame's history is shared with the tab and the game, so go straight to the page
941
+ if (window.parent !== window) go(lastView || "games");
942
+ else history.length > 1 ? history.back() : (location.hash = "#games");
796
943
  }
797
944
 
798
945
  // ---------- Utilities ----------
@@ -836,6 +983,9 @@
836
983
  // Newest first. Add an entry here with every publish; its version should match package.json.
837
984
  // Each has: new (features), games (added/removed/fixed games), fixes (bugs). Leave a list out if empty.
838
985
  const CHANGELOG = [
986
+ { version: "1.0.44", date: "2026-11-12",
987
+ new: ["🔒 Private chat rooms: host a room, share its 6-character code, and chat with just the people who have it. Each room gets its own tab next to Public, with a dot when someone posts (rooms last 24 hours)", "🎨 Every holiday theme now has its own drawn scene, with fireworks on New Year's and the Fourth of July and a countdown to the big day", "🎉 New themes: Super Bowl weekend, April Fools' Day, summer break and back to school", "Holiday colors now show on every page, not just the home page", "💰 A Tycoon section on the Games page: Monkey Mart, Adventure Capitalist, Hardware Tycoon, OpenTTD and more", "The site now looks like Google Classroom loading for a moment before the loading screen (it follows the tab disguise setting)"],
988
+ fixes: ["In the .svg version, Back from a game no longer lands on a list of files"] },
839
989
  { version: "1.0.43", date: "2026-11-10",
840
990
  new: [], fixes: ["The .svg version now shows your tab disguise (like Google Classroom) in the browser tab", "In the .svg version, the link back to the normal site is at the bottom of the Games page and opens its Games page"] },
841
991
  { version: "1.0.42", date: "2026-11-10",
@@ -1354,7 +1504,12 @@
1354
1504
  loadScript(`https://www.gstatic.com/firebasejs/${v}/firebase-database-compat.js`),
1355
1505
  loadScript(`https://www.gstatic.com/firebasejs/${v}/firebase-auth-compat.js`),
1356
1506
  ]);
1357
- return window.firebase.initializeApp(CFG.firebase, "rug");
1507
+ const app = window.firebase.initializeApp(CFG.firebase, "rug");
1508
+ if (CFG.firebaseEmulator) { // local testing only (see config.js)
1509
+ const [host, port] = String(CFG.firebaseEmulator).split(":");
1510
+ app.database().useEmulator(host, Number(port));
1511
+ }
1512
+ return app;
1358
1513
  })().catch((err) => { console.warn("Firebase unavailable:", err); return null; });
1359
1514
  }
1360
1515
  return firebaseApp;
@@ -1473,7 +1628,10 @@
1473
1628
  };
1474
1629
  const HIDE_AFTER_REPORTS = Infinity;
1475
1630
  // Each room keeps its own messages, typing and "in chat" list; names, bans, mutes and settings are shared
1476
- function roomPath(x) { return chat.room === "live" ? `live/chat/${x}` : `chat/${x}`; } // reports are switched off: nothing is hidden automatically
1631
+ // A private room is "room:<CODE>": everything in it lives under rooms/<CODE> (see "Private chat rooms" below)
1632
+ function roomCode() { return chat.room.startsWith("room:") ? chat.room.slice(5) : null; }
1633
+ function roomPath(x) { const c = roomCode(); return c ? `rooms/${c}/${x}` : chat.room === "live" ? `live/chat/${x}` : `chat/${x}`; } // reports are switched off: nothing is hidden automatically
1634
+ function flagsPath() { const c = roomCode(); return c ? `roomFlags/${c}` : "chat/flags"; }
1477
1635
  const ADMIN_NAME = "Richard"; // what the admin's messages show as (reserved: the database refuses it from non-admins)
1478
1636
  function setAdminName() {
1479
1637
  $("chat-name").value = ADMIN_NAME;
@@ -1516,6 +1674,7 @@
1516
1674
  log.innerHTML = `<p class="chat-empty" id="chat-empty">No messages yet. Say hi!</p>`;
1517
1675
  const db = app.database();
1518
1676
  watchChatState(db);
1677
+ await restoreRoom(db); // back into the private room this browser was in, if it's still open
1519
1678
  listenRoom(db);
1520
1679
  watchChatReset(db);
1521
1680
  }
@@ -1548,14 +1707,33 @@
1548
1707
  }
1549
1708
  }
1550
1709
  function listenRoom(db) {
1551
- const log = $("chat-log"), room = chat.room;
1710
+ const log = $("chat-log"), room = chat.room, tab = activeTab();
1711
+ tabUnread.delete(tab);
1552
1712
  log.innerHTML = `<p class="chat-empty" id="chat-empty">${room === "live" ? "No messages yet. Say hi to the stream!" : "No messages yet. Say hi!"}</p>`;
1553
- $("chat-text").placeholder = room === "live" ? "Chat with the stream…" : "Say something… (drop a photo here)";
1713
+ $("chat-text").placeholder = room === "live" ? "Chat with the stream…" : roomCode() ? "Say something in this room…" : "Say something… (drop a photo here)";
1554
1714
  if (chat.ref) chat.ref.off(); // reconnecting (signed in/out): drop the old listener so messages don't double
1555
1715
  chat.resetAt = lastChatReset();
1556
- const ref = chat.ref = db.ref(roomPath("messages")).orderByChild("ts").startAt(chat.resetAt).limitToLast(60);
1716
+ // poll votes and report counts belong to the room being shown
1717
+ chat.votesRef?.off();
1718
+ chat.flagsRef?.off();
1719
+ chat.votes = {};
1720
+ chat.flags = {};
1721
+ chat.votesRef = db.ref(roomPath("votes"));
1722
+ chat.votesRef.on("value", (s) => { chat.votes = s.val() || {}; updatePolls(); }, () => {});
1723
+ chat.flagsRef = db.ref(flagsPath());
1724
+ chat.flagsRef.on("value", (s) => {
1725
+ chat.flags = {};
1726
+ s.forEach((c) => { chat.flags[c.key] = c.numChildren(); });
1727
+ log.querySelectorAll(".chat-msg").forEach(applyFlags);
1728
+ if (chat.admin && !roomCode()) renderReported();
1729
+ }, () => {});
1730
+ watchRoomMeta(db);
1731
+ syncTabWatchers(db);
1732
+ // the main chat starts fresh each day; a private room shows everything since it was made (it only lasts a day)
1733
+ const ref = chat.ref = db.ref(roomPath("messages")).orderByChild("ts").startAt(roomCode() ? 0 : chat.resetAt).limitToLast(60);
1557
1734
  ref.on("child_added", (snap) => {
1558
1735
  const m = snap.val();
1736
+ if (m && Number(m.ts)) markTabSeen(tab, Number(m.ts));
1559
1737
  const div = renderMessage(snap.key, m);
1560
1738
  if (!div) return;
1561
1739
  $("chat-empty")?.remove();
@@ -1578,6 +1756,7 @@
1578
1756
  }
1579
1757
  async function switchRoom(room) {
1580
1758
  if (room === chat.room) return;
1759
+ markTabSeen(activeTab()); // everything in the tab you're leaving counts as read
1581
1760
  stopTyping();
1582
1761
  typing.ref = null;
1583
1762
  if (hereOn && hereRef) hereRef.remove().catch(() => {});
@@ -1589,6 +1768,226 @@
1589
1768
  if (app) listenRoom(app.database());
1590
1769
  }
1591
1770
 
1771
+ // ---------- Private chat rooms ----------
1772
+ // Host a room and get a 6-character code; anyone who types the code joins it. A room is rooms/<CODE> in the
1773
+ // database (readable only by people who know the code), with roomMeta/<CODE> = { host, ts }. Rooms stop
1774
+ // working 24 hours after they're made. The same word filter, bans and mutes apply, the host can delete any
1775
+ // message in the room or close it, and the site owner can open any room (Settings lists them).
1776
+ const ROOM_LIFE = 24 * 60 * 60e3, ROOM_KEY = "rug-room", ROOMS_KEY = "rug-rooms";
1777
+ const ROOM_LETTERS = "ABCDEFGHJKMNPQRSTUVWXYZ23456789"; // no I, L, O, 0 or 1: they get misread
1778
+ const cleanRoomCode = (s) => String(s || "").toUpperCase().replace(/[^A-Z0-9]/g, "").slice(0, 6);
1779
+ function isRoomHost() { return !!roomCode() && !!chat.roomMeta && chat.roomMeta.host === chat.uid; }
1780
+ function serverNow() { return Date.now() + (typing.offset || 0); }
1781
+ function roomMsg(text) { $("room-msg").textContent = text || ""; }
1782
+ // every room this browser has been in (code -> when it was made), so expired ones can be cleaned up later
1783
+ function rememberRoom(code, ts) {
1784
+ const all = store.get(ROOMS_KEY, {});
1785
+ if (ts) all[code] = ts; else delete all[code];
1786
+ store.set(ROOMS_KEY, all);
1787
+ }
1788
+ function deleteRoom(db, code) {
1789
+ return db.ref().update({ [`rooms/${code}`]: null, [`roomMeta/${code}`]: null, [`roomFlags/${code}`]: null });
1790
+ }
1791
+ function sweepMyRooms(db) {
1792
+ for (const [code, ts] of Object.entries(store.get(ROOMS_KEY, {}))) {
1793
+ if (serverNow() - ts < ROOM_LIFE) continue;
1794
+ rememberRoom(code, null);
1795
+ deleteRoom(db, code).catch(() => {});
1796
+ }
1797
+ }
1798
+ async function restoreRoom(db) {
1799
+ sweepMyRooms(db);
1800
+ const code = cleanRoomCode(store.get(ROOM_KEY, ""));
1801
+ if (code.length !== 6) return;
1802
+ try {
1803
+ const meta = (await db.ref(`roomMeta/${code}`).once("value")).val();
1804
+ if (meta && serverNow() - meta.ts < ROOM_LIFE) { chat.room = `room:${code}`; return; }
1805
+ } catch { /* older rules, or offline */ }
1806
+ store.set(ROOM_KEY, "");
1807
+ }
1808
+ async function hostRoom() {
1809
+ const app = await getFirebase();
1810
+ if (!app || !chat.uid) return roomMsg("Chat isn't connected yet.");
1811
+ if (chat.banned) return roomMsg("You're banned from chat.");
1812
+ const db = app.database(), TS = window.firebase.database.ServerValue.TIMESTAMP;
1813
+ const code = [...crypto.getRandomValues(new Uint32Array(6))].map((n) => ROOM_LETTERS[n % ROOM_LETTERS.length]).join("");
1814
+ try {
1815
+ await db.ref().update({ [`roomMeta/${code}`]: { host: chat.uid, ts: TS }, [`roomLast/${chat.uid}`]: TS });
1816
+ } catch {
1817
+ return roomMsg("Couldn't make a room. You can make one a minute, so wait a bit and try again.");
1818
+ }
1819
+ rememberRoom(code, serverNow());
1820
+ enterRoom(code);
1821
+ toast(`Room ${code} is open. Share the code to let people in.`);
1822
+ }
1823
+ async function joinRoom(raw) {
1824
+ const code = cleanRoomCode(raw);
1825
+ if (code.length !== 6) return roomMsg("Room codes are 6 letters and numbers.");
1826
+ const app = await getFirebase();
1827
+ if (!app || !chat.uid) return roomMsg("Chat isn't connected yet.");
1828
+ const db = app.database();
1829
+ let meta = null;
1830
+ try { meta = (await db.ref(`roomMeta/${code}`).once("value")).val(); } catch { return roomMsg("Couldn't check that code. Try again."); }
1831
+ if (!meta) return roomMsg("No room has that code. Check it and try again.");
1832
+ if (serverNow() - meta.ts >= ROOM_LIFE) { deleteRoom(db, code).catch(() => {}); return roomMsg("That room has closed. Rooms last 24 hours."); }
1833
+ rememberRoom(code, meta.ts);
1834
+ enterRoom(code);
1835
+ }
1836
+ function enterRoom(code) {
1837
+ store.set(ROOM_KEY, code);
1838
+ $("room-panel").hidden = true;
1839
+ $("room-code").value = "";
1840
+ roomMsg("");
1841
+ switchRoom(`room:${code}`);
1842
+ }
1843
+ function leaveRoom(note) {
1844
+ const code = roomCode();
1845
+ if (code) { rememberRoom(code, null); tabUnread.delete(code); }
1846
+ store.set(ROOM_KEY, "");
1847
+ switchRoom("main");
1848
+ if (note) chatNote(note);
1849
+ }
1850
+ // ---------- Chat tabs: Public, then every room this browser is in, then "+ Room" ----------
1851
+ // Tabs you're not looking at keep a light watch (their newest message) to show a dot when someone posts there.
1852
+ const TAB_SEEN_KEY = "rug-tab-seen", pageOpenedAt = Date.now();
1853
+ const tabSeen = store.get(TAB_SEEN_KEY, {}), tabUnread = new Set(), tabWatch = {};
1854
+ const activeTab = () => roomCode() || "main";
1855
+ function myRooms() {
1856
+ return Object.entries(store.get(ROOMS_KEY, {}))
1857
+ .filter(([c, ts]) => cleanRoomCode(c) === c && c.length === 6 && serverNow() - ts < ROOM_LIFE)
1858
+ .sort((a, b) => a[1] - b[1]).map(([c]) => c);
1859
+ }
1860
+ function markTabSeen(tab, ts) {
1861
+ tabSeen[tab] = Math.max(tabSeen[tab] || 0, ts || serverNow());
1862
+ store.set(TAB_SEEN_KEY, tabSeen);
1863
+ }
1864
+ function renderTabs() {
1865
+ const bar = $("chat-tabs"), active = activeTab();
1866
+ bar.hidden = chat.room === "live";
1867
+ const tab = (id, label, title) => `<button class="chat-tab${tabUnread.has(id) ? " unread" : ""}" type="button" role="tab" data-tab="${id}" aria-selected="${id === active}" title="${title}">${label}</button>`;
1868
+ bar.innerHTML = tab("main", "Public", "The public chat") +
1869
+ myRooms().map((c) => tab(c, `🔒 ${c}`, `Private room ${c}`)).join("") +
1870
+ `<button class="chat-tab add" type="button" id="room-open" aria-expanded="${!$("room-panel").hidden}" title="Host or join a private room">+ Room</button>`;
1871
+ }
1872
+ function syncTabWatchers(db) {
1873
+ const want = new Set(chat.room === "live" ? [] : ["main", ...myRooms()]);
1874
+ want.delete(activeTab());
1875
+ for (const id of Object.keys(tabWatch)) if (!want.has(id)) { tabWatch[id].off(); delete tabWatch[id]; }
1876
+ for (const id of want) {
1877
+ if (tabWatch[id]) continue;
1878
+ tabWatch[id] = db.ref(id === "main" ? "chat/messages" : `rooms/${id}/messages`).orderByChild("ts").limitToLast(1);
1879
+ tabWatch[id].on("child_added", (s) => {
1880
+ const m = s.val();
1881
+ if (!m || m.uid === chat.uid || !(Number(m.ts) > (tabSeen[id] || pageOpenedAt))) return;
1882
+ if (id === "main") noteNewMessage(m, false); // the side bar's chat dot
1883
+ if (activeTab() !== id) { tabUnread.add(id); renderTabs(); }
1884
+ }, () => { // the room closed or ran out: drop its tab
1885
+ delete tabWatch[id];
1886
+ if (id === "main") return;
1887
+ rememberRoom(id, null);
1888
+ tabUnread.delete(id);
1889
+ renderTabs();
1890
+ });
1891
+ }
1892
+ }
1893
+ async function closeRoom() {
1894
+ const code = roomCode();
1895
+ if (!code || !(isRoomHost() || chat.admin)) return;
1896
+ if (!confirm("Close this room for everyone? All its messages are deleted.")) return;
1897
+ try { await deleteRoom((await getFirebase()).database(), code); } // everyone's page then sees the room is gone and leaves
1898
+ catch { chatNote("Couldn't close the room. Try again.", true); }
1899
+ }
1900
+ // Follows the open room's entry: fills the strip above the messages, and leaves when the room closes or runs out
1901
+ function watchRoomMeta(db) {
1902
+ chat.metaRef?.off();
1903
+ chat.metaRef = null;
1904
+ chat.roomMeta = null;
1905
+ clearInterval(chat.roomTimer);
1906
+ const code = roomCode();
1907
+ renderRoomStrip();
1908
+ if (!code) return;
1909
+ const gone = (note) => { rememberRoom(code, null); if (roomCode() === code) leaveRoom(note); };
1910
+ chat.metaRef = db.ref(`roomMeta/${code}`);
1911
+ chat.metaRef.on("value", (s) => {
1912
+ const meta = s.val();
1913
+ if (!meta || serverNow() - meta.ts >= ROOM_LIFE) { gone("That private room has closed."); return; }
1914
+ chat.roomMeta = meta;
1915
+ rememberRoom(code, meta.ts);
1916
+ renderRoomStrip();
1917
+ }, () => gone("That private room has closed."));
1918
+ chat.roomTimer = setInterval(() => {
1919
+ if (chat.roomMeta && serverNow() - chat.roomMeta.ts >= ROOM_LIFE) { deleteRoom(db, code).catch(() => {}); gone("That private room has closed. Rooms last 24 hours."); }
1920
+ else renderRoomStrip();
1921
+ }, 30000);
1922
+ }
1923
+ function renderRoomStrip() {
1924
+ const code = roomCode();
1925
+ $("room-strip").hidden = !code;
1926
+ $("chat-log").classList.toggle("host", isRoomHost());
1927
+ renderTabs();
1928
+ if (!code) return;
1929
+ $("room-strip-code").textContent = code;
1930
+ $("room-strip-left").textContent = chat.roomMeta ? `closes in ${fmtWait(chat.roomMeta.ts + ROOM_LIFE - serverNow())}` : "";
1931
+ $("room-close").hidden = !(isRoomHost() || chat.admin);
1932
+ }
1933
+ // Owner: every open room (Settings → Tools), with how many reports each has. Expired ones are deleted here too.
1934
+ let roomsAdminWatched = false;
1935
+ function watchRoomsAdmin(db) {
1936
+ if (roomsAdminWatched) return;
1937
+ roomsAdminWatched = true;
1938
+ let metas = {}, flags = {};
1939
+ const draw = () => {
1940
+ const rows = Object.entries(metas).filter(([, m]) => m && serverNow() - m.ts < ROOM_LIFE).sort((a, b) => b[1].ts - a[1].ts);
1941
+ $("rooms-count").textContent = rows.length ? `(${rows.length})` : "";
1942
+ $("rooms-list").innerHTML = !rows.length ? `<p class="none">No private rooms open.</p>` : rows.map(([code, m]) => {
1943
+ const n = Object.keys(flags[code] || {}).length;
1944
+ return `<div class="report" data-code="${escapeHtml(code)}">${n ? `<span class="kind broken">🚩 ${n}</span>` : ""}` +
1945
+ `<div class="body"><span class="game">${escapeHtml(code)}</span><div class="meta">Closes in ${fmtWait(m.ts + ROOM_LIFE - serverNow())}</div></div>` +
1946
+ `<button class="mod" type="button" data-room="open">Open</button><button class="mod" type="button" data-room="close">Close</button></div>`;
1947
+ }).join("");
1948
+ };
1949
+ db.ref("roomMeta").on("value", (s) => {
1950
+ metas = s.val() || {};
1951
+ for (const [code, m] of Object.entries(metas)) if (!m || serverNow() - m.ts >= ROOM_LIFE) deleteRoom(db, code).catch(() => {});
1952
+ draw();
1953
+ }, () => { roomsAdminWatched = false; });
1954
+ db.ref("roomFlags").on("value", (s) => { flags = s.val() || {}; draw(); }, () => {});
1955
+ }
1956
+ function bindRooms() {
1957
+ $("chat-tabs").addEventListener("click", (e) => {
1958
+ const b = e.target.closest(".chat-tab");
1959
+ if (!b) return;
1960
+ if (b.id === "room-open") {
1961
+ $("room-panel").hidden = !$("room-panel").hidden;
1962
+ roomMsg("");
1963
+ renderTabs();
1964
+ if (!$("room-panel").hidden) $("room-code").focus();
1965
+ return;
1966
+ }
1967
+ const id = b.dataset.tab;
1968
+ $("room-panel").hidden = true;
1969
+ store.set(ROOM_KEY, id === "main" ? "" : id);
1970
+ switchRoom(id === "main" ? "main" : `room:${id}`);
1971
+ if (id === activeTab()) renderTabs();
1972
+ });
1973
+ $("room-host").addEventListener("click", hostRoom);
1974
+ $("room-join").addEventListener("submit", (e) => { e.preventDefault(); joinRoom($("room-code").value); });
1975
+ $("room-code").addEventListener("input", () => { $("room-code").value = cleanRoomCode($("room-code").value); });
1976
+ $("room-leave").addEventListener("click", () => leaveRoom());
1977
+ $("room-close").addEventListener("click", closeRoom);
1978
+ $("room-copy").addEventListener("click", async () => {
1979
+ try { await navigator.clipboard.writeText(roomCode()); toast("Room code copied ✓"); } catch { toast(`Room code: ${roomCode()}`); }
1980
+ });
1981
+ $("rooms-list").addEventListener("click", async (e) => {
1982
+ const b = e.target.closest("[data-room]"), code = b?.closest(".report")?.dataset.code;
1983
+ if (!code || !chat.admin) return;
1984
+ if (b.dataset.room === "open") { enterRoom(code); go("chat"); return; }
1985
+ if (confirm(`Close room ${code} for everyone? All its messages are deleted.`)) {
1986
+ try { await deleteRoom((await getFirebase()).database(), code); } catch {}
1987
+ }
1988
+ });
1989
+ }
1990
+
1592
1991
  // One chat row: text, a sticker or a photo, plus its buttons (shown by CSS for who may use them)
1593
1992
  function renderMessage(key, m) {
1594
1993
  if (!m || typeof m.name !== "string") return null;
@@ -1672,7 +2071,6 @@
1672
2071
 
1673
2072
  // Live chat state: owner settings (slow mode, lock, extra words), my mute/ban, and report counts
1674
2073
  function watchChatState(db) {
1675
- db.ref("chat/votes").on("value", (s) => { chat.votes = s.val() || {}; updatePolls(); });
1676
2074
  db.ref("chat/settings").on("value", (s) => {
1677
2075
  chat.settings = s.val() || {};
1678
2076
  updateChatStatus();
@@ -1684,12 +2082,6 @@
1684
2082
  }, () => {});
1685
2083
  db.ref(`chat/mutes/${chat.uid}`).on("value", (s) => { chat.mutedUntil = Number(s.val()?.until) || 0; updateChatStatus(); }, () => {});
1686
2084
  db.ref(`chat/banned/${chat.uid}`).on("value", (s) => { chat.banned = s.exists(); updateChatStatus(); }, () => {});
1687
- db.ref("chat/flags").on("value", (s) => {
1688
- chat.flags = {};
1689
- s.forEach((c) => { chat.flags[c.key] = c.numChildren(); });
1690
- $("chat-log").querySelectorAll(".chat-msg").forEach(applyFlags);
1691
- if (chat.admin) renderReported();
1692
- }, () => {});
1693
2085
  clearInterval(chat.statusTimer);
1694
2086
  chat.statusTimer = setInterval(updateChatStatus, 15000); // mutes run out on their own
1695
2087
  }
@@ -1792,7 +2184,7 @@
1792
2184
  if (act === "vote") {
1793
2185
  if (!chat.uid) return;
1794
2186
  const i = Number(btn.dataset.i), mineNow = (chat.votes[key] || {})[chat.uid];
1795
- try { await (await getFirebase()).database().ref(`chat/votes/${key}/${chat.uid}`).set(mineNow === i ? null : i); }
2187
+ try { await (await getFirebase()).database().ref(roomPath(`votes/${key}/${chat.uid}`)).set(mineNow === i ? null : i); }
1796
2188
  catch { chatNote(blockedReason() || "Your vote didn't count. Try again.", true); }
1797
2189
  return;
1798
2190
  }
@@ -1800,10 +2192,10 @@
1800
2192
  const db = (await getFirebase()).database();
1801
2193
  try {
1802
2194
  if (act === "report" && !mine) {
1803
- await db.ref(`chat/flags/${key}/${chat.uid}`).set(true);
1804
- chatNote(`Reported. Messages with ${HIDE_AFTER_REPORTS} reports are hidden until the owner looks at them.`);
1805
- } else if (act === "delete" && (mine || chat.admin)) {
1806
- await db.ref().update({ [roomPath(`messages/${key}`)]: null, ...(row.dataset.media ? { [`chat/media/${row.dataset.media}`]: null } : {}) });
2195
+ await db.ref(`${flagsPath()}/${key}/${chat.uid}`).set(true);
2196
+ chatNote("Reported. The site owner will take a look.");
2197
+ } else if (act === "delete" && (mine || chat.admin || isRoomHost())) {
2198
+ await db.ref().update({ [roomPath(`messages/${key}`)]: null, ...(row.dataset.media ? { [roomPath(`media/${row.dataset.media}`)]: null } : {}) });
1807
2199
  } else if (!chat.admin || mine) {
1808
2200
  return;
1809
2201
  } else if (act === "purge") {
@@ -1884,7 +2276,7 @@
1884
2276
  $("admin-chat-tools").hidden = !on;
1885
2277
  $("admin-quotes").hidden = !on;
1886
2278
  if (on) { watchQuoteAdmin(); renderQuoteAdmin(); }
1887
- if (on) { watchReports(); watchPunished(app.database()); fillChatTools(); renderReported(); }
2279
+ if (on) { watchReports(); watchPunished(app.database()); watchRoomsAdmin(app.database()); fillChatTools(); renderReported(); }
1888
2280
  else unwatchReports();
1889
2281
  }
1890
2282
 
@@ -1905,7 +2297,7 @@
1905
2297
  }
1906
2298
  // Messages people reported, newest reports first, with keep / delete / delete-all buttons
1907
2299
  async function renderReported() {
1908
- if (!chat.admin) return;
2300
+ if (!chat.admin || roomCode()) return; // this list is the main chat's; rooms with reports show under "Private rooms"
1909
2301
  const keys = Object.keys(chat.flags).filter((k) => chat.flags[k] > 0);
1910
2302
  $("reported-count").textContent = keys.length ? `(${keys.length})` : "";
1911
2303
  if (!keys.length) { $("reported-list").innerHTML = `<p class="none">Nothing reported.</p>`; return; }
@@ -3411,9 +3803,9 @@
3411
3803
  const app = await getFirebase();
3412
3804
  if (!app || !chat.uid || !chatSender()) return false;
3413
3805
  const db = app.database(), TS = window.firebase.database.ServerValue.TIMESTAMP;
3414
- const id = db.ref("chat/media").push().key;
3806
+ const id = db.ref(roomPath("media")).push().key;
3415
3807
  try {
3416
- await db.ref().update({ [`chat/media/${id}`]: { data, uid: chat.uid, ts: TS }, [`chat/mediaLast/${chat.uid}`]: TS });
3808
+ await db.ref().update({ [roomPath(`media/${id}`)]: { data, uid: chat.uid, ts: TS }, [`chat/mediaLast/${chat.uid}`]: TS });
3417
3809
  } catch {
3418
3810
  chatNote(blockedReason() || "Wait a few seconds between videos and voice notes.", true);
3419
3811
  return false;
@@ -3511,7 +3903,7 @@
3511
3903
  async function playMedia(btn, kind) {
3512
3904
  btn.disabled = true;
3513
3905
  try {
3514
- const snap = await (await getFirebase()).database().ref(`chat/media/${btn.dataset.media}`).once("value");
3906
+ const snap = await (await getFirebase()).database().ref(roomPath(`media/${btn.dataset.media}`)).once("value");
3515
3907
  const data = snap.val()?.data;
3516
3908
  if (typeof data !== "string" || !/^data:(video|audio)\/(webm|mp4|ogg)/.test(data)) throw new Error("gone");
3517
3909
  const el = document.createElement(kind === "voice" ? "audio" : "video");
@@ -3872,6 +4264,14 @@
3872
4264
  const el = els.frame;
3873
4265
  (el.requestFullscreen || el.webkitRequestFullscreen)?.call(el);
3874
4266
  });
4267
+ // "#…" links: with a <base> tag (.svg version) the browser would open the package folder instead
4268
+ document.addEventListener("click", (e) => {
4269
+ const link = e.target.closest?.('a[href^="#"]');
4270
+ if (!link || link.dataset.nav || e.defaultPrevented) return;
4271
+ e.preventDefault();
4272
+ const hash = link.getAttribute("href");
4273
+ if (hash.length > 1) location.hash = hash;
4274
+ });
3875
4275
  window.addEventListener("hashchange", () => route());
3876
4276
  window.addEventListener("popstate", () => route());
3877
4277
  }
@@ -3941,6 +4341,16 @@
3941
4341
 
3942
4342
  // ---------- Boot screen + auto-update ----------
3943
4343
  const boot = { el: $("boot"), fill: $("boot-fill"), msg: $("boot-msg"), ver: $("boot-ver"), timer: 0, pct: 0 };
4344
+ // The "Google Classroom" screen stays about 1.8s from when the page started, then fades to the boot screen.
4345
+ // Resolves once it's gone (right away when the disguise is off).
4346
+ function runSplash() {
4347
+ const el = $("gc-splash");
4348
+ if (!el || document.documentElement.classList.contains("no-splash") || settings.disguise === "off") { el?.remove(); return Promise.resolve(); }
4349
+ return new Promise((done) => setTimeout(() => {
4350
+ el.classList.add("gone");
4351
+ setTimeout(() => { el.remove(); done(); }, 300);
4352
+ }, Math.max(0, 1800 - performance.now())));
4353
+ }
3944
4354
  function startBoot() {
3945
4355
  boot.msg.textContent = "Loading…";
3946
4356
  boot.timer = setInterval(() => {
@@ -3980,6 +4390,7 @@
3980
4390
  let firstVisit = false;
3981
4391
  try { firstVisit = !Object.keys(localStorage).some((k) => k.startsWith("rug-")); } catch {}
3982
4392
  loadSettings();
4393
+ const splash = runSplash();
3983
4394
  startBoot();
3984
4395
  initTheme();
3985
4396
  // the side bar can be tucked away (remembered); a small tab on the left edge brings it back
@@ -4007,6 +4418,7 @@
4007
4418
  $("chat-log").addEventListener("click", mentionFromName);
4008
4419
  bindAdmin();
4009
4420
  bindChatTools();
4421
+ bindRooms();
4010
4422
  bindChatExtras();
4011
4423
  bindChatMedia();
4012
4424
  bindPolls();
@@ -4020,8 +4432,8 @@
4020
4432
  // First visit: only messages from now on count as new.
4021
4433
  if (store.get(CHAT_SEEN_KEY, null) === null) store.set(CHAT_SEEN_KEY, Date.now());
4022
4434
  if (CFG.firebase) { openChat(); startQuotes(); }
4023
- // just long enough that the loading screen doesn't flash
4024
- const minShow = new Promise((r) => setTimeout(r, 300));
4435
+ // the loading screen shows for a moment after the Classroom screen, so it doesn't just flash
4436
+ const minShow = splash.then(() => new Promise((r) => setTimeout(r, 700)));
4025
4437
  const update = newerVersionUrl(2500);
4026
4438
  try {
4027
4439
  const res = await fetch("games.json", { cache: "no-cache" });