@ywkrlerche/richardwho 1.0.39 → 1.0.40

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
@@ -205,7 +205,6 @@
205
205
  if (ids === community.shown) return;
206
206
  community.shown = ids;
207
207
  startMarquee();
208
- renderHomeApps();
209
208
  updateLiveBadges();
210
209
  }
211
210
  async function startCommunity() {
@@ -239,6 +238,22 @@
239
238
  await db.ref().update({ [`stats/plays/${fbKey(game.id)}`]: FV.increment(1), [`stats/playLast/${user.uid}`]: FV.TIMESTAMP });
240
239
  } catch { /* too soon after the last one, or offline: not counted */ }
241
240
  }
241
+ // The soundboard (a game frame on this page) reads everyone's sound plays and counts its own here
242
+ window.rugSoundStats = {
243
+ async counts() {
244
+ const app = await getFirebase();
245
+ if (!app) return {};
246
+ try { return (await app.database().ref("stats/sounds").once("value")).val() || {}; } catch { return {}; }
247
+ },
248
+ async count(key) {
249
+ const app = await getFirebase();
250
+ if (!app) return;
251
+ try {
252
+ const user = await signedInUser(app), FV = window.firebase.database.ServerValue;
253
+ await app.database().ref().update({ [`stats/sounds/${fbKey(key)}`]: FV.increment(1), [`stats/soundLast/${user.uid}`]: FV.TIMESTAMP });
254
+ } catch { /* too soon after the last one, or offline: not counted */ }
255
+ },
256
+ };
242
257
  function notePlayStop() {
243
258
  const ref = community.playingRef;
244
259
  if (!ref) return;
@@ -259,15 +274,6 @@
259
274
  $("gotd").hidden = false;
260
275
  }
261
276
 
262
- // ---------- Home: shortcut tiles for popular games under the search bar ----------
263
- function renderHomeApps() {
264
- const list = popularList(12);
265
- $("home-apps").innerHTML = list.map((g) => {
266
- const url = logoUrl(g);
267
- const art = url ? `<img src="${url}" alt="" decoding="async">` : `<span style="background:${gradient(g)}">${escapeHtml(initials(g.name).slice(0, 2))}</span>`;
268
- return `<button class="home-app" type="button" data-id="${escapeHtml(g.id)}" title="${escapeHtml(g.name)}"><span class="home-app-icon">${art}</span><span class="home-app-name">${escapeHtml(g.name)}</span></button>`;
269
- }).join("");
270
- }
271
277
 
272
278
  // ---------- Halloween: decorations on the home page, all of October ----------
273
279
  // Drawn once (SVG, emoji and gradients); only the bats and the ghost move, using cheap transforms.
@@ -286,35 +292,181 @@
286
292
  }
287
293
  return `<svg class="web ${flip ? "right" : "left"}" viewBox="0 0 270 270"><path d="${d}"/></svg>`;
288
294
  }
289
- // ---------- Themes (Settings → Theme): Auto picks Halloween in October, Christmas in December, else Black ----------
290
- const THEMES = ["auto", "black", "white", "halloween", "christmas"];
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.
298
+ 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 },
305
+ };
306
+ const HOLIDAYS = ["halloween", "christmas", ...Object.keys(FESTS)];
307
+ const SPOOKY_FALL = { items: ["🍂", "🍁", "🍬", "🦇"], count: 50 };
308
+ const THEMES = ["auto", "black", "white"];
291
309
  function resolveTheme(t) {
292
- if (THEMES.includes(t) && t !== "auto") return t;
293
- const m = new Date().getMonth();
294
- return m === 9 ? "halloween" : m === 11 ? "christmas" : "black";
310
+ return t === "black" || t === "white" ? t : (window.rugHoliday && window.rugHoliday()) || "black";
295
311
  }
312
+ let shownTheme = null;
296
313
  function applySiteTheme(choice) {
297
314
  const t = resolveTheme(choice);
315
+ shownTheme = t;
298
316
  const root = document.documentElement;
299
317
  root.dataset.theme = t === "white" ? "light" : "dark";
300
- root.classList.toggle("halloween", t === "halloween");
301
- root.classList.toggle("christmas", t === "christmas");
302
- $("theme-color").content = { white: "#f6f6f8", halloween: "#110820", christmas: "#0b1424" }[t] || "#000000";
318
+ for (const h of HOLIDAYS) root.classList.toggle(h, t === h);
319
+ root.classList.toggle("fest", !!FESTS[t]);
320
+ $("theme-color").content = { white: "#f6f6f8", halloween: "#110820", christmas: "#0b1424" }[t] || FESTS[t]?.color || "#000000";
303
321
  if (t === "halloween" && !document.querySelector(".spooky")) buildHalloween(); // scenery is only drawn once it's needed
304
322
  if (t === "christmas" && !document.querySelector(".xmas")) buildChristmas();
323
+ if (FESTS[t]) buildFest(t);
324
+ fallers.set(t);
325
+ }
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
+ function buildFest(t) {
329
+ const old = document.querySelector(".festive");
330
+ if (old?.dataset.fest === t) return;
331
+ old?.remove();
332
+ const spots = ["right:4vw", "right:calc(4vw + 78px)", "right:calc(4vw + 150px)", "right:calc(4vw + 206px)"];
333
+ $("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("")}
336
+ </div>`);
305
337
  }
338
+
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.
341
+ const fallers = {
342
+ 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,
344
+ still: matchMedia("(prefers-reduced-motion: reduce)").matches,
345
+ set(theme) {
346
+ const fall = theme === "halloween" ? SPOOKY_FALL : FESTS[theme];
347
+ this.kind = theme === "christmas" ? "snow" : fall ? "emoji" : null;
348
+ if (!this.kind) { cancelAnimationFrame(this.raf); this.raf = 0; if (this.canvas) this.canvas.hidden = true; return; }
349
+ if (!this.canvas) this.init();
350
+ this.items = fall?.items || [];
351
+ const small = innerWidth < 720;
352
+ this.target = this.kind === "snow" ? (small ? 150 : 320) : Math.round(fall.count * (small ? .5 : 1));
353
+ this.list = Array.from({ length: this.target }, () => this.make(true));
354
+ this.canvas.hidden = false;
355
+ this.start();
356
+ },
357
+ init() {
358
+ $("view-home").insertAdjacentHTML("beforeend", `<canvas class="fallers" aria-hidden="true"></canvas>`);
359
+ this.canvas = document.querySelector(".fallers");
360
+ this.ctx = this.canvas.getContext("2d");
361
+ this.resize();
362
+ addEventListener("resize", () => this.resize());
363
+ addEventListener("pointermove", (e) => { this.px = e.clientX - this.ox; this.py = e.clientY - this.oy; }, { passive: true });
364
+ document.addEventListener("pointerleave", () => { this.px = this.py = -1e4; });
365
+ document.addEventListener("visibilitychange", () => this.start());
366
+ document.addEventListener("click", (e) => {
367
+ if (!this.kind || $("view-home").hidden) return;
368
+ if (e.target.closest("a, button, input, select, textarea, label, [role=button], .rail, .quote-strip, .home-search")) return;
369
+ this.burst(e.clientX, e.clientY, 18);
370
+ });
371
+ },
372
+ resize() {
373
+ const r = this.canvas.getBoundingClientRect(), d = Math.min(devicePixelRatio || 1, 2);
374
+ this.ox = r.left; this.oy = r.top;
375
+ if (r.width === this.w && r.height === this.h) return;
376
+ this.w = r.width; this.h = r.height;
377
+ this.canvas.width = Math.round(r.width * d);
378
+ this.canvas.height = Math.round(r.height * d);
379
+ this.ctx.setTransform(d, 0, 0, d, 0, 0);
380
+ },
381
+ make(spread, x, y) {
382
+ const snow = this.kind === "snow";
383
+ return {
384
+ x: x ?? Math.random() * this.w, y: y ?? (spread ? Math.random() * this.h : -30), vx: 0, vy: 0,
385
+ fall: snow ? .35 + Math.random() * .8 : .45 + Math.random() * .6,
386
+ size: snow ? 1.2 + Math.random() * 2.8 : 16 + Math.random() * 14,
387
+ phase: Math.random() * 6.28, sway: .4 + Math.random() * .8, rot: Math.random() * 6.28, spin: (Math.random() - .5) * .03,
388
+ item: snow ? null : this.items[Math.floor(Math.random() * this.items.length)], extra: false,
389
+ };
390
+ },
391
+ burst(cx, cy, n) {
392
+ if (!this.kind) return;
393
+ for (let i = 0; i < n && this.list.length < this.target + 160; i++) {
394
+ const p = this.make(false, cx - this.ox, cy - this.oy), a = Math.random() * Math.PI * 2, s = 2 + Math.random() * 4;
395
+ p.vx = Math.cos(a) * s; p.vy = Math.sin(a) * s - 2; p.extra = true;
396
+ this.list.push(p);
397
+ }
398
+ this.start();
399
+ },
400
+ // each emoji is drawn once onto a small canvas and then stamped, much cheaper than drawing text every frame
401
+ sprite(ch) {
402
+ if (!this.sprites[ch]) {
403
+ const c = document.createElement("canvas"), x = c.getContext("2d");
404
+ c.width = c.height = 64;
405
+ x.font = '48px "Segoe UI Emoji", "Apple Color Emoji", "Noto Color Emoji", sans-serif';
406
+ x.textAlign = "center"; x.textBaseline = "middle";
407
+ x.fillText(ch, 32, 36);
408
+ this.sprites[ch] = c;
409
+ }
410
+ return this.sprites[ch];
411
+ },
412
+ start() {
413
+ if (this.raf || !this.kind) return;
414
+ this.last = performance.now();
415
+ this.raf = requestAnimationFrame((t) => this.frame(t));
416
+ },
417
+ frame(t) {
418
+ this.raf = 0;
419
+ if (!this.kind || document.hidden) return;
420
+ if ($("view-home").hidden) { setTimeout(() => this.start(), 500); return; }
421
+ const dt = Math.min(3, (t - this.last) / 16.7);
422
+ this.last = t;
423
+ if (t - this.measured > 1000) { this.measured = t; this.resize(); } // the side bar can slide in or out
424
+ const ctx = this.ctx, snow = this.kind === "snow", R = 110, damp = Math.pow(.95, dt);
425
+ ctx.clearRect(0, 0, this.w, this.h);
426
+ if (snow) { ctx.fillStyle = "rgba(255, 255, 255, .85)"; ctx.beginPath(); } else ctx.globalAlpha = .85;
427
+ for (let i = this.list.length - 1; i >= 0; i--) {
428
+ const p = this.list[i];
429
+ const dx = p.x - this.px, dy = p.y - this.py, d2 = dx * dx + dy * dy;
430
+ 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
+ p.vx *= damp; p.vy *= damp; p.phase += .02 * dt; p.rot += p.spin * dt;
432
+ 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) {
435
+ if (p.extra) { this.list.splice(i, 1); continue; }
436
+ Object.assign(p, this.make(false));
437
+ }
438
+ if (snow) { ctx.moveTo(p.x + p.size, p.y); ctx.arc(p.x, p.y, p.size, 0, 6.283); }
439
+ else { ctx.setTransform(1, 0, 0, 1, 0, 0); ctx.scale(this.canvas.width / this.w, this.canvas.height / this.h); ctx.translate(p.x, p.y); ctx.rotate(p.rot); ctx.drawImage(this.sprite(p.item), -p.size / 2, -p.size / 2, p.size, p.size); }
440
+ }
441
+ if (snow) ctx.fill();
442
+ else { const d = this.canvas.width / this.w; ctx.setTransform(d, 0, 0, d, 0, 0); ctx.globalAlpha = 1; }
443
+ if (!this.still) this.raf = requestAnimationFrame((t2) => this.frame(t2));
444
+ },
445
+ };
446
+
306
447
  function buildChristmas() {
307
448
  const colors = ["#ef4444", "#facc15", "#22c55e", "#3b82f6"];
308
449
  const bulbs = Array.from({ length: 26 }, (_, i) => `<i style="left:${(i + .5) * (100 / 26)}%;top:${10 + Math.sin(i * 1.3) * 5}px;--c:${colors[i % 4]};animation-delay:${(i % 5) * -.45}s"></i>`).join("");
309
450
  const tree = (x, h) => `<path d="M${x} ${200 - h}l${h * .32} ${h * .45}h-${h * .12}l${h * .22} ${h * .3}h-${h * .1}l${h * .25} ${h * .25}h-${h * 1.34}l${h * .25}-${h * .25}h-${h * .1}l${h * .22}-${h * .3}h-${h * .12}Z"/>`;
310
451
  $("view-home").insertAdjacentHTML("afterbegin", `<div class="xmas" aria-hidden="true">
311
452
  <div class="lights"><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>${bulbs}</div>
312
- <div class="snow s1"></div><div class="snow s2"></div>
313
453
  <svg class="hills" viewBox="0 0 1600 240" preserveAspectRatio="xMidYMax slice">
314
454
  <g class="pines">${tree(120, 120)}${tree(230, 80)}${tree(1380, 140)}${tree(1500, 90)}</g>
315
455
  <path class="snowbank" d="M0 200C200 170 420 190 640 180S1100 165 1300 182 1520 186 1600 176V240H0Z"/>
316
456
  </svg>
317
- <span class="xmas-tree">🎄</span><span class="gift g1">🎁</span><span class="gift g2">🎁</span><span class="snowman">☃️</span>
457
+ <span class="xmas-tree">🎄</span><span class="gift g1">🎁</span><span class="gift g2">🎁</span>
458
+ <svg class="snowman" viewBox="0 0 100 150">
459
+ <path d="M30 64 8 46M14 51l-6 1M12 49l1-7M70 64 92 46M86 51l6 1M88 49l-1-7" stroke="#6b4423" stroke-width="3" stroke-linecap="round" fill="none"/>
460
+ <circle cx="50" cy="114" r="32" fill="#f8fafc" stroke="#cbd5e1" stroke-width="1.5"/>
461
+ <circle cx="50" cy="68" r="23" fill="#f8fafc" stroke="#cbd5e1" stroke-width="1.5"/>
462
+ <circle cx="50" cy="34" r="17" fill="#f8fafc" stroke="#cbd5e1" stroke-width="1.5"/>
463
+ <g fill="#1f2937"><circle cx="50" cy="60" r="2.4"/><circle cx="50" cy="70" r="2.4"/><circle cx="50" cy="80" r="2.4"/>
464
+ <circle cx="43" cy="41" r="1.2"/><circle cx="47" cy="43" r="1.2"/><circle cx="53" cy="43" r="1.2"/><circle cx="57" cy="41" r="1.2"/>
465
+ <circle cx="44" cy="30" r="2.3"/><circle cx="56" cy="30" r="2.3"/></g>
466
+ <path d="M50 34l15 3-15 3Z" fill="#f97316"/>
467
+ <path d="M33 49c10 5 24 5 34 0v6c-10 5-24 5-34 0Z" fill="#dc2626"/><path d="M58 53l4 16h-7l-2-15Z" fill="#b91c1c"/>
468
+ <rect x="30" y="17" width="40" height="5" rx="2" fill="#111827"/><rect x="37" y="0" width="26" height="19" rx="2" fill="#111827"/><rect x="37" y="12" width="26" height="4" fill="#dc2626"/>
469
+ </svg>
318
470
  </div>`);
319
471
  }
320
472
  function buildHalloween() {
@@ -684,6 +836,9 @@
684
836
  // Newest first. Add an entry here with every publish; its version should match package.json.
685
837
  // Each has: new (features), games (added/removed/fixed games), fixes (bugs). Leave a list out if empty.
686
838
  const CHANGELOG = [
839
+ { version: "1.0.40", date: "2026-10-30",
840
+ new: ["Send videos in chat: from your computer (📷) or record one with the camera (📸)", "Voice notes in chat (🎤)", "🔊 Soundboard: Kawhi Leonard's laugh, and sort by Popular or My most used", "🎉 Holiday themes switch by themselves: New Year's, Valentine's Day, St. Patrick's Day, Easter, Fourth of July, Halloween, Thanksgiving and Christmas", "🎨 Theme setting is now Holiday, Black or White", "❄️ Christmas: snow you can push around and click, and a snowman"],
841
+ fixes: ["The home page is cleaner and fits small Chromebook screens", "Animated stickers were removed", "The Christmas lights are no longer hidden behind the quote of the day"] },
687
842
  { version: "1.0.39", date: "2026-10-29",
688
843
  fixes: ["Old daily challenge scores clean themselves up after 2 days"] },
689
844
  { version: "1.0.38", date: "2026-10-29",
@@ -1366,7 +1521,7 @@
1366
1521
  }
1367
1522
  async function sweepOldMessages(db) {
1368
1523
  const dayAgo = Date.now() - 86400000;
1369
- for (const path of ["chat/messages"]) {
1524
+ for (const path of ["chat/messages", "chat/media"]) {
1370
1525
  try {
1371
1526
  const old = await db.ref(path).orderByChild("ts").endAt(dayAgo).limitToFirst(200).once("value");
1372
1527
  const changes = {};
@@ -1418,23 +1573,26 @@
1418
1573
  }
1419
1574
 
1420
1575
  // One chat row: text, a sticker or a photo, plus its buttons (shown by CSS for who may use them)
1421
- const STICKER_URL = (code) => `https://fonts.gstatic.com/s/e/notoemoji/latest/${code}/512.webp`;
1422
1576
  function renderMessage(key, m) {
1423
1577
  if (!m || typeof m.name !== "string") return null;
1424
1578
  let body;
1425
1579
  if (typeof m.text === "string") {
1426
1580
  // mask again on display, so words added to the owner's list later get hidden in old messages too
1427
1581
  body = escapeHtml(maskText(m.text)).replace(/(^|\s)@([\w-]{2,16})/g, '$1<span class="at">@$2</span>');
1428
- } else if (typeof m.sticker === "string" && STICKERS.includes(m.sticker)) {
1429
- body = `<img class="chat-sticker" src="${STICKER_URL(m.sticker)}" alt="sticker" width="96" height="96" loading="lazy">`; } else if (typeof m.img === "string" && /^data:image\/(webp|jpeg);base64,[A-Za-z0-9+/=]+$/.test(m.img)) {
1582
+ } else if (typeof m.sticker === "string" && /^[0-9a-f]{2,6}(_[0-9a-f]{2,6})*$/.test(m.sticker)) {
1583
+ body = `<span class="chat-sticker">${String.fromCodePoint(...m.sticker.split("_").map((h) => parseInt(h, 16)))}</span>`; // stickers were removed: older ones show as a still emoji
1584
+ } else if (typeof m.img === "string" && /^data:image\/(webp|jpeg);base64,[A-Za-z0-9+/=]+$/.test(m.img)) {
1430
1585
  body = `<button class="chat-photo-btn" type="button" data-act="view" title="Open photo"><img class="chat-photo" src="${m.img}" alt="Photo from ${escapeHtml(m.name)}" loading="lazy"></button>`;
1431
1586
  } else if (m.poll && typeof m.poll.q === "string" && pollOptions(m.poll).length >= 2) {
1432
1587
  body = pollHtml(key, m.poll);
1588
+ } else if (m.media && (m.media.kind === "video" || m.media.kind === "voice") && typeof m.media.id === "string") {
1589
+ body = mediaHtml(m);
1433
1590
  } else return null;
1434
1591
  const t = new Date(m.ts || Date.now());
1435
1592
  const div = document.createElement("div");
1436
1593
  const mine = m.uid === chat.uid;
1437
1594
  div.className = "chat-msg" + (mine ? " me" : "") + (m.img ? " photo" : "") + (m.sticker ? " sticker" : "") + (m.poll ? " has-poll" : "");
1595
+ if (m.media) div.dataset.media = m.media.id;
1438
1596
  if (m.poll) div.pollData = m.poll; // kept so the bars can be redrawn as votes come in
1439
1597
  div.dataset.key = key;
1440
1598
  div.dataset.uid = m.uid || "";
@@ -1533,7 +1691,7 @@
1533
1691
  function slowSeconds() { return chat.admin ? 0 : Number(chat.settings.slowMode) || 0; } // no cooldown unless the owner turns on slow mode
1534
1692
  function updateChatStatus() {
1535
1693
  const why = blockedReason();
1536
- ["chat-text", "emoji-btn", "photo-btn", "cam-btn"] /* Send stays clickable: the admin code works even when chat is locked */.forEach((id) => { if ($(id)) $(id).disabled = !!why; });
1694
+ ["chat-text", "emoji-btn", "photo-btn", "cam-btn", "voice-btn"] /* Send stays clickable: the admin code works even when chat is locked */.forEach((id) => { if ($(id)) $(id).disabled = !!why; });
1537
1695
  const slow = Number(chat.settings.slowMode) || 0;
1538
1696
  $("chat-status").textContent = why || (chat.settings.locked ? "🔒 Chat is locked (only you can post)" : slow ? `🐢 Slow mode: one message every ${slow}s` : "");
1539
1697
  $("chat-status").classList.toggle("err", !!why);
@@ -1610,6 +1768,7 @@
1610
1768
  const row = btn.closest(".chat-msg");
1611
1769
  const act = btn.dataset.act, uid = row.dataset.uid, name = row.dataset.name, key = row.dataset.key;
1612
1770
  if (act === "view") { openPhoto(row.querySelector("img").src); return; }
1771
+ if (act === "play-media") { playMedia(btn, btn.classList.contains("chat-voice") ? "voice" : "video"); return; }
1613
1772
  if (act === "vote") {
1614
1773
  if (!chat.uid) return;
1615
1774
  const i = Number(btn.dataset.i), mineNow = (chat.votes[key] || {})[chat.uid];
@@ -1624,7 +1783,7 @@
1624
1783
  await db.ref(`chat/flags/${key}/${chat.uid}`).set(true);
1625
1784
  chatNote(`Reported. Messages with ${HIDE_AFTER_REPORTS} reports are hidden until the owner looks at them.`);
1626
1785
  } else if (act === "delete" && (mine || chat.admin)) {
1627
- await db.ref().update({ [roomPath(`messages/${key}`)]: null });
1786
+ await db.ref().update({ [roomPath(`messages/${key}`)]: null, ...(row.dataset.media ? { [`chat/media/${row.dataset.media}`]: null } : {}) });
1628
1787
  } else if (!chat.admin || mine) {
1629
1788
  return;
1630
1789
  } else if (act === "purge") {
@@ -1927,7 +2086,7 @@
1927
2086
  });
1928
2087
  $("admin-clear").addEventListener("click", async () => {
1929
2088
  if (!chat.admin || !confirm("Delete every chat message for everyone?")) return;
1930
- try { await (await getFirebase()).database().ref("chat/messages").remove(); }
2089
+ try { await (await getFirebase()).database().ref().update({ "chat/messages": null, "chat/media": null }); }
1931
2090
  catch { alert("Couldn't clear the chat."); }
1932
2091
  });
1933
2092
  }
@@ -3110,19 +3269,7 @@
3110
3269
  side(!phone() && store.get("rug-ai-side", true));
3111
3270
  }
3112
3271
 
3113
- // ---------- Emoji picker and stickers ----------
3114
- // Stickers are Google's Noto animated emoji (CC BY 4.0), sent by code so only these can ever appear.
3115
- // Grouped into tabs in the picker; every code here was checked to exist on Google's server
3116
- const STICKER_GROUPS = [
3117
- ["😂", ["1f602", "1f923", "1f62d", "1f480", "1f973", "1f921", "1f60e", "1f92f", "1f97a", "1f911", "1f644", "1f60d", "1f622", "1f624", "1f976", "1f975", "1f60b", "1f634", "1f47b", "1f600", "1f601", "1f604", "1f605", "1f606", "1f609", "1f60a", "1f607", "1f970", "1f618", "1f61c", "1f92a", "1f92d", "1f92b", "1f914", "1f928", "1f610", "1f611", "1f636", "1f60f", "1f612", "1f62c", "1f925", "1f60c", "1f614", "1f62a", "1f924", "1f637", "1f912", "1f915", "1f922", "1f927", "1f635", "1f920", "1f913", "1f9d0", "1f615", "1f61f", "1f641", "1f62e", "1f62f", "1f632", "1f633", "1f628", "1f630", "1f625", "1f631", "1f616", "1f623", "1f61e", "1f613", "1f629", "1f62b", "1f971", "1f620", "1f621", "1f92c", "1f608", "1f47f", "1f4a9", "1f47d", "1f916", "1f63a", "1f638", "1f639", "1f63b", "1f63f", "1f640", "1f648", "1f649", "1f64a"]],
3118
- ["👍", ["1f44d", "1f44f", "1f64f", "1f4aa", "1f918", "2764_fe0f", "1f9e0", "1f440", "1f48b", "1f498", "1f494", "1f4a5", "1f4ab", "1f44b", "1f44c", "1f90c", "270c_fe0f", "1f91e", "1f91f", "1f919", "1f44a", "1f91b", "1f64c", "1f450", "1f932", "1f91d", "1f485", "1f933", "1f441_fe0f", "1f483"]],
3119
- ["🐶", ["1f40d", "1f431", "1f98a", "1f43b", "1f43c", "1f981", "1f42e", "1f438", "1f427", "1f426", "1f985", "1f989", "1f987", "1f43a", "1f984", "1f41d", "1f98b", "1f40c", "1f41e", "1f422", "1f996", "1f995", "1f419", "1f988", "1f42c", "1f433", "1f40a", "1f998", "1f415", "1f413", "1f9a9", "1f407", "1f43f_fe0f", "1f994"]],
3120
- ["🌈", ["1f340", "1f335", "1f339", "1f337", "1f308", "26a1", "2744_fe0f", "2603_fe0f", "1f30a", "1f30b", "1f30d", "2b50", "2604_fe0f", "1f30c"]],
3121
- ["🍕", ["1f34e", "1f349", "1f353", "1f951", "1f33d", "1f37f", "1f354", "1f355", "1f32d", "1f32e", "1f942", "1f37e", "1f379", "2615", "1f382", "1f369", "1f36a"]],
3122
- ["🏆", ["1f3c6", "1f389", "26bd", "1f3c0", "26be", "1f3be", "1f3b3", "1f3af", "1f3b2", "1f3b8", "1f3b7", "1f941", "1f3ac", "1f388", "1f381", "1f38a", "1f386", "1f383", "1f947", "1f3c1"]],
3123
- ["🚀", ["1f680", "1f525", "1f4af", "1f31f", "1f697", "1f6b2", "1f6f8", "2708_fe0f", "1f6a8", "1f4bb", "1f4f8", "1f48e", "1f514", "1f4a1", "1f50b", "23f0", "231b", "2705", "274c", "2757", "2753", "1f198", "1f4ac", "1f5ff", "1f47e"]],
3124
- ];
3125
- const STICKERS = STICKER_GROUPS.flatMap(([, list]) => list);
3272
+ // ---------- Emoji picker ----------
3126
3273
  const EMOJI_GROUPS = [
3127
3274
  ["😀", "😀😃😄😁😆😅😂🤣🥲😊😇🙂🙃😉😌😍🥰😘😋😛😜🤪😝🤑🤗🤭🤫🤔🤐🤨😐😑😶😏😒🙄😬😮‍💨🤥😴🤤😪😮😯😲🥱😳🥺😢😭😤😠😡🤯😱😨😰🥶🥵😵‍💫🤠🥳😎🤓🧐😈👻💀☠️🤡💩🤖👽"],
3128
3275
  ["👍", "👍👎👏🙌👐🤝🙏✌️🤞🤟🤘👌🤌🤏👈👉👆👇☝️✋🤚🖐️👋🤙💪🫡🫶"],
@@ -3133,22 +3280,16 @@
3133
3280
  ];
3134
3281
  function buildPicker() {
3135
3282
  const seg = (s) => [...new Intl.Segmenter(undefined, { granularity: "grapheme" }).segment(s)].map((x) => x.segment);
3136
- $("picker-tabs").innerHTML = EMOJI_GROUPS.map(([icon], i) => `<button type="button" role="tab" data-tab="${i}" aria-selected="${i === 0}" title="Emoji">${icon}</button>`).join("") +
3137
- `<button type="button" role="tab" data-tab="stickers" aria-selected="false" class="tab-stickers">Stickers</button>`;
3283
+ $("picker-tabs").innerHTML = EMOJI_GROUPS.map(([icon], i) => `<button type="button" role="tab" data-tab="${i}" aria-selected="${i === 0}" title="Emoji">${icon}</button>`).join("");
3138
3284
  const showTab = (tab) => {
3139
3285
  $("picker-tabs").querySelectorAll("[data-tab]").forEach((b) => b.setAttribute("aria-selected", b.dataset.tab === String(tab)));
3140
- $("picker-grid").className = "picker-grid" + (tab === "stickers" ? " stickers" : "");
3141
- $("picker-grid").innerHTML = tab === "stickers"
3142
- ? STICKER_GROUPS.map(([icon, list]) => `<p class="picker-head">${icon}</p>` +
3143
- list.map((c) => `<button type="button" data-sticker="${c}" title="Send sticker"><img src="${STICKER_URL(c)}" alt="" width="56" height="56" loading="lazy"></button>`).join("")).join("")
3144
- : seg(EMOJI_GROUPS[tab][1]).map((e) => `<button type="button" data-emoji="${e}">${e}</button>`).join("");
3286
+ $("picker-grid").innerHTML = seg(EMOJI_GROUPS[tab][1]).map((e) => `<button type="button" data-emoji="${e}">${e}</button>`).join("");
3145
3287
  };
3146
3288
  showTab(0);
3147
- $("picker-tabs").addEventListener("click", (e) => { const b = e.target.closest("[data-tab]"); if (b) showTab(/^\d+$/.test(b.dataset.tab) ? Number(b.dataset.tab) : b.dataset.tab); });
3289
+ $("picker-tabs").addEventListener("click", (e) => { const b = e.target.closest("[data-tab]"); if (b) showTab(Number(b.dataset.tab)); });
3148
3290
  $("picker-grid").addEventListener("click", async (e) => {
3149
- const em = e.target.closest("[data-emoji]"), st = e.target.closest("[data-sticker]");
3291
+ const em = e.target.closest("[data-emoji]");
3150
3292
  if (em) insertAtCursor($("chat-text"), em.dataset.emoji);
3151
- if (st && await postMessage({ sticker: st.dataset.sticker })) togglePicker(false);
3152
3293
  });
3153
3294
  }
3154
3295
  function insertAtCursor(input, text) {
@@ -3164,6 +3305,212 @@
3164
3305
  $("emoji-btn").setAttribute("aria-expanded", open);
3165
3306
  }
3166
3307
 
3308
+ // ---------- Videos and voice notes in chat ----------
3309
+ // A clip is re-recorded small (videos: 15 s max, 360 px, ~300 kbps; voice: 60 s max, 24 kbps) and stored at
3310
+ // chat/media/<id>; the chat message only carries a little preview picture and the length, so nobody downloads
3311
+ // a clip until they press play. Videos get the same nude check as photos, on a few frames.
3312
+ const VIDEO_MAX = 15, VOICE_MAX = 60, MEDIA_MAX_CHARS = 1000000;
3313
+ const recMime = (kind) => (kind === "video"
3314
+ ? ["video/webm;codecs=vp8,opus", "video/webm", "video/mp4"] : ["audio/webm;codecs=opus", "audio/webm", "audio/ogg", "audio/mp4"])
3315
+ .find((t) => window.MediaRecorder && MediaRecorder.isTypeSupported(t)) || "";
3316
+ const blobToDataUrl = (blob) => new Promise((ok, fail) => { const r = new FileReader(); r.onload = () => ok(r.result); r.onerror = fail; r.readAsDataURL(blob); });
3317
+ const fmtSecs = (s) => `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, "0")}`;
3318
+ // Records a stream until stop() or the time limit; resolves with the recorded Blob
3319
+ function recordStream(stream, kind, maxSecs, onTick) {
3320
+ const rec = new MediaRecorder(stream, { mimeType: recMime(kind), videoBitsPerSecond: 280000, audioBitsPerSecond: kind === "video" ? 32000 : 24000 });
3321
+ const parts = [], started = Date.now();
3322
+ rec.ondataavailable = (e) => { if (e.data.size) parts.push(e.data); };
3323
+ const done = new Promise((ok) => { rec.onstop = () => ok(new Blob(parts, { type: rec.mimeType.split(";")[0] })); });
3324
+ const tick = setInterval(() => {
3325
+ const secs = (Date.now() - started) / 1000;
3326
+ onTick?.(secs);
3327
+ if (secs >= maxSecs && rec.state === "recording") rec.stop();
3328
+ }, 200);
3329
+ rec.start(1000);
3330
+ return { done: done.finally(() => clearInterval(tick)), stop: () => { if (rec.state === "recording") rec.stop(); }, started };
3331
+ }
3332
+ // A video file from the computer: played into a small canvas (and its sound into a recorder), first 15 s only
3333
+ async function shrinkVideoFile(file, onTick) {
3334
+ const v = document.createElement("video");
3335
+ v.src = URL.createObjectURL(file);
3336
+ v.playsInline = true;
3337
+ await new Promise((ok, fail) => { v.onloadedmetadata = ok; v.onerror = () => fail(new Error("unreadable")); });
3338
+ const k = Math.min(1, 360 / Math.max(v.videoWidth, v.videoHeight));
3339
+ const c = document.createElement("canvas");
3340
+ c.width = Math.round(v.videoWidth * k / 2) * 2; c.height = Math.round(v.videoHeight * k / 2) * 2;
3341
+ const g = c.getContext("2d");
3342
+ const ac = new AudioContext(), out = ac.createMediaStreamDestination();
3343
+ ac.createMediaElementSource(v).connect(out); // the sound goes to the recording, not the speakers
3344
+ const stream = new MediaStream([...c.captureStream(24).getVideoTracks(), ...out.stream.getAudioTracks()]);
3345
+ let raf = 0;
3346
+ const draw = () => { g.drawImage(v, 0, 0, c.width, c.height); raf = requestAnimationFrame(draw); };
3347
+ await v.play();
3348
+ draw();
3349
+ const r = recordStream(stream, "video", Math.min(VIDEO_MAX, v.duration || VIDEO_MAX), onTick);
3350
+ v.onended = () => r.stop();
3351
+ const blob = await r.done;
3352
+ cancelAnimationFrame(raf); v.pause(); ac.close(); URL.revokeObjectURL(v.src);
3353
+ return { blob, secs: Math.min(VIDEO_MAX, v.duration || VIDEO_MAX), longer: (v.duration || 0) > VIDEO_MAX + 0.5 };
3354
+ }
3355
+ // Grabs a few frames of a recorded video: a preview picture, and (for the nude check) frames to classify
3356
+ async function videoFrames(blob) {
3357
+ const v = document.createElement("video");
3358
+ v.src = URL.createObjectURL(blob); v.muted = true; v.playsInline = true;
3359
+ await new Promise((ok, fail) => { v.onloadeddata = ok; v.onerror = () => fail(new Error("unreadable")); });
3360
+ // recorded WebM often reports no length until it's been read to the end
3361
+ if (!isFinite(v.duration)) { v.currentTime = 1e9; await new Promise((ok) => { v.ontimeupdate = () => { v.ontimeupdate = null; ok(); }; }); }
3362
+ const len = isFinite(v.duration) ? v.duration : 1;
3363
+ const grab = async (t, side) => {
3364
+ v.currentTime = Math.min(len - 0.05, Math.max(0, t));
3365
+ await new Promise((ok) => { v.onseeked = ok; });
3366
+ const k = side / Math.max(v.videoWidth, v.videoHeight), c = document.createElement("canvas");
3367
+ c.width = Math.max(1, Math.round(v.videoWidth * k)); c.height = Math.max(1, Math.round(v.videoHeight * k));
3368
+ c.getContext("2d").drawImage(v, 0, 0, c.width, c.height);
3369
+ return c;
3370
+ };
3371
+ const frames = [];
3372
+ for (const f of [0.15, 0.5, 0.85]) frames.push(await grab(len * f, 224));
3373
+ const poster = (await grab(len * 0.15, 240)).toDataURL("image/jpeg", 0.6);
3374
+ URL.revokeObjectURL(v.src);
3375
+ return { frames, poster, secs: len };
3376
+ }
3377
+ async function videoIsOk(frames) {
3378
+ const model = await loadNsfw();
3379
+ for (const c of frames) {
3380
+ const sq = document.createElement("canvas"); sq.width = sq.height = 224;
3381
+ sq.getContext("2d").drawImage(c, 0, 0, 224, 224);
3382
+ const p = Object.fromEntries((await model.classify(sq)).map((x) => [x.className, x.probability]));
3383
+ if ((p.Porn || 0) > 0.35 || (p.Hentai || 0) > 0.35 || (p.Sexy || 0) > 0.6) return false;
3384
+ }
3385
+ return true;
3386
+ }
3387
+ // Posts a clip: the data first (its own write), then the chat message that points to it
3388
+ async function postMedia(kind, blob, secs, poster) {
3389
+ const data = await blobToDataUrl(blob);
3390
+ if (data.length > MEDIA_MAX_CHARS) { chatNote(kind === "video" ? "That video came out too big to send. Try a shorter one." : "That voice note is too long.", true); return false; }
3391
+ const app = await getFirebase();
3392
+ if (!app || !chat.uid || !chatSender()) return false;
3393
+ const db = app.database(), TS = window.firebase.database.ServerValue.TIMESTAMP;
3394
+ const id = db.ref("chat/media").push().key;
3395
+ try {
3396
+ await db.ref().update({ [`chat/media/${id}`]: { data, uid: chat.uid, ts: TS }, [`chat/mediaLast/${chat.uid}`]: TS });
3397
+ } catch {
3398
+ chatNote(blockedReason() || "Wait a few seconds between videos and voice notes.", true);
3399
+ return false;
3400
+ }
3401
+ return postMessage({ media: { kind, id, secs: Math.max(1, Math.round(secs)), ...(poster && poster.length <= 14000 ? { poster } : {}) } });
3402
+ }
3403
+ async function sendVideoFile(file) {
3404
+ if (!file || !/^video\//.test(file.type)) { chatNote("That isn't a video.", true); return; }
3405
+ if (file.size > 300 * 1048576) { chatNote("That video is too big (300 MB max).", true); return; }
3406
+ if (!recMime("video")) { chatNote("This browser can't send videos.", true); return; }
3407
+ if (!chatSender()) return;
3408
+ $("photo-btn").disabled = true;
3409
+ try {
3410
+ chatNote("Getting the video ready…");
3411
+ const { blob, longer } = await shrinkVideoFile(file, (s) => chatNote(`Getting the video ready… ${Math.floor(s)}s of ${VIDEO_MAX}s max`));
3412
+ chatNote("Checking video…");
3413
+ const { frames, poster, secs } = await videoFrames(blob);
3414
+ if (!(await videoIsOk(frames))) { chatNote("That video can't be sent here.", true); return; }
3415
+ if (await postMedia("video", blob, secs, poster)) chatNote(longer ? `Sent the first ${VIDEO_MAX} seconds.` : "");
3416
+ } catch {
3417
+ chatNote("Couldn't use that video. Try a different one.", true);
3418
+ } finally {
3419
+ $("photo-btn").disabled = !!blockedReason();
3420
+ $("photo-input").value = "";
3421
+ }
3422
+ }
3423
+ // 📸 window, video mode: record up to 15 s with sound, preview, then send
3424
+ let camRec = null, camClip = null;
3425
+ async function recordCamVideo() {
3426
+ if (camRec) { camRec.stop(); return; }
3427
+ if (!recMime("video")) { $("cam-msg").textContent = "This browser can't record video."; return; }
3428
+ try {
3429
+ const mic = await navigator.mediaDevices.getUserMedia({ audio: true });
3430
+ const stream = new MediaStream([...camStream.getVideoTracks(), ...mic.getAudioTracks()]);
3431
+ $("cam-rec").textContent = "■ Stop";
3432
+ $("cam-snap").hidden = true;
3433
+ camRec = recordStream(stream, "video", VIDEO_MAX, (s) => { $("cam-msg").textContent = `Recording ${fmtSecs(s)} / ${fmtSecs(VIDEO_MAX)}`; });
3434
+ const blob = await camRec.done;
3435
+ mic.getTracks().forEach((t) => t.stop());
3436
+ camRec = null;
3437
+ camClip = blob;
3438
+ $("cam-video").hidden = true;
3439
+ $("cam-clip").hidden = false;
3440
+ $("cam-clip").src = URL.createObjectURL(blob);
3441
+ $("cam-msg").textContent = "";
3442
+ $("cam-rec").hidden = true; $("cam-retake").hidden = false; $("cam-send").hidden = false;
3443
+ $("cam-rec").textContent = "● Record video";
3444
+ } catch {
3445
+ camRec = null;
3446
+ $("cam-msg").textContent = "Couldn't use your microphone. Allow it in the browser and try again.";
3447
+ }
3448
+ }
3449
+ async function sendCamClip() {
3450
+ const blob = camClip;
3451
+ closeCamera();
3452
+ if (!blob) return;
3453
+ try {
3454
+ chatNote("Checking video…");
3455
+ const { frames, poster, secs } = await videoFrames(blob);
3456
+ if (!(await videoIsOk(frames))) { chatNote("That video can't be sent here.", true); return; }
3457
+ if (await postMedia("video", blob, secs, poster)) chatNote("");
3458
+ } catch { chatNote("Couldn't send that video.", true); }
3459
+ }
3460
+ // 🎤 voice notes: press to record (60 s max), then Send or Cancel
3461
+ let voiceRec = null, voiceMic = null;
3462
+ async function startVoice() {
3463
+ if (voiceRec || !chatSender()) return;
3464
+ if (!recMime("voice")) { chatNote("This browser can't record voice notes.", true); return; }
3465
+ try { voiceMic = await navigator.mediaDevices.getUserMedia({ audio: true }); }
3466
+ catch { chatNote("Couldn't use your microphone. Allow it in the browser and try again.", true); return; }
3467
+ $("voice-bar").hidden = false;
3468
+ voiceRec = recordStream(voiceMic, "voice", VOICE_MAX, (s) => { $("voice-time").textContent = `${fmtSecs(s)} / ${fmtSecs(VOICE_MAX)}`; });
3469
+ voiceRec.done.then((blob) => { voiceRec.blob = blob; });
3470
+ }
3471
+ async function finishVoice(send) {
3472
+ if (!voiceRec) return;
3473
+ const r = voiceRec;
3474
+ r.stop();
3475
+ const blob = await r.done;
3476
+ voiceMic?.getTracks().forEach((t) => t.stop());
3477
+ voiceRec = voiceMic = null;
3478
+ $("voice-bar").hidden = true;
3479
+ $("voice-time").textContent = "0:00";
3480
+ const secs = (Date.now() - r.started) / 1000;
3481
+ if (send && secs >= 1 && await postMedia("voice", blob, Math.min(secs, VOICE_MAX))) chatNote("");
3482
+ }
3483
+ // A clip in the chat: a play card; the clip itself is fetched the first time someone presses play
3484
+ function mediaHtml(m) {
3485
+ const md = m.media, secs = fmtSecs(Number(md.secs) || 0);
3486
+ if (md.kind === "voice") return `<button class="chat-voice" type="button" data-act="play-media" data-media="${escapeHtml(md.id)}">▶ <span>Voice note</span><span class="chat-media-len">${secs}</span></button>`;
3487
+ const poster = typeof md.poster === "string" && /^data:image\/(jpeg|webp);base64,[A-Za-z0-9+/=]+$/.test(md.poster) ? md.poster : "";
3488
+ return `<button class="chat-video" type="button" data-act="play-media" data-media="${escapeHtml(md.id)}">` +
3489
+ `${poster ? `<img src="${poster}" alt="">` : ""}<span class="chat-video-play">▶</span><span class="chat-media-len">${secs}</span></button>`;
3490
+ }
3491
+ async function playMedia(btn, kind) {
3492
+ btn.disabled = true;
3493
+ try {
3494
+ const snap = await (await getFirebase()).database().ref(`chat/media/${btn.dataset.media}`).once("value");
3495
+ const data = snap.val()?.data;
3496
+ if (typeof data !== "string" || !/^data:(video|audio)\/(webm|mp4|ogg)/.test(data)) throw new Error("gone");
3497
+ const el = document.createElement(kind === "voice" ? "audio" : "video");
3498
+ el.className = kind === "voice" ? "chat-voice-player" : "chat-video-player";
3499
+ el.src = data; el.controls = true; el.autoplay = true; el.playsInline = true;
3500
+ el.controlsList = "nodownload"; // play in the chat; no download button
3501
+ btn.replaceWith(el);
3502
+ } catch {
3503
+ btn.disabled = false;
3504
+ btn.querySelector(".chat-media-len").textContent = "unavailable";
3505
+ }
3506
+ }
3507
+ function bindChatMedia() {
3508
+ $("voice-btn").addEventListener("click", startVoice);
3509
+ $("voice-send").addEventListener("click", () => finishVoice(true));
3510
+ $("voice-cancel").addEventListener("click", () => finishVoice(false));
3511
+ $("cam-rec").addEventListener("click", recordCamVideo);
3512
+ }
3513
+
3167
3514
  // ---------- Photos: drag and drop, paste, or 📷 ----------
3168
3515
  // Posted straight away (no review). Before sending, a nudity detector (NSFW.js, runs in this browser)
3169
3516
  // checks the picture; the photo is re-drawn, which also strips hidden data like location, and shrunk to ≤ ~100 KB.
@@ -3241,8 +3588,9 @@
3241
3588
  }
3242
3589
  }
3243
3590
  function showCamShot(taken) {
3244
- $("cam-video").hidden = taken; $("cam-shot").hidden = !taken;
3245
- $("cam-snap").hidden = taken; $("cam-retake").hidden = !taken; $("cam-send").hidden = !taken;
3591
+ $("cam-video").hidden = taken; $("cam-shot").hidden = !taken; $("cam-clip").hidden = true;
3592
+ $("cam-snap").hidden = taken; $("cam-rec").hidden = taken; $("cam-retake").hidden = !taken; $("cam-send").hidden = !taken;
3593
+ camClip = null;
3246
3594
  }
3247
3595
  function snapCamera() {
3248
3596
  const v = $("cam-video"), c = $("cam-shot");
@@ -3254,6 +3602,9 @@
3254
3602
  showCamShot(true);
3255
3603
  }
3256
3604
  function closeCamera() {
3605
+ camRec?.stop();
3606
+ $("cam-clip").pause();
3607
+ $("cam-clip").removeAttribute("src");
3257
3608
  camStream?.getTracks().forEach((t) => t.stop());
3258
3609
  camStream = null;
3259
3610
  $("cam-video").srcObject = null;
@@ -3269,7 +3620,7 @@
3269
3620
  $("cam-btn").addEventListener("click", openCamera);
3270
3621
  $("cam-snap").addEventListener("click", snapCamera);
3271
3622
  $("cam-retake").addEventListener("click", () => showCamShot(false));
3272
- $("cam-send").addEventListener("click", sendCamPhoto);
3623
+ $("cam-send").addEventListener("click", () => (camClip ? sendCamClip() : sendCamPhoto()));
3273
3624
  $("cam-close").addEventListener("click", closeCamera);
3274
3625
  $("cam-wrap").addEventListener("click", (e) => { if (e.target === $("cam-wrap")) closeCamera(); });
3275
3626
  $("emoji-btn").addEventListener("click", () => togglePicker());
@@ -3279,7 +3630,8 @@
3279
3630
  });
3280
3631
  $("picker").addEventListener("keydown", (e) => { if (e.key === "Escape") { togglePicker(false); $("emoji-btn").focus(); } });
3281
3632
  $("photo-btn").addEventListener("click", () => $("photo-input").click());
3282
- $("photo-input").addEventListener("change", () => sendPhoto($("photo-input").files[0]));
3633
+ const sendFile = (f) => (f && f.type.startsWith("video/") ? sendVideoFile(f) : sendPhoto(f));
3634
+ $("photo-input").addEventListener("change", () => sendFile($("photo-input").files[0]));
3283
3635
  const box = $("chat-box");
3284
3636
  let depth = 0;
3285
3637
  box.addEventListener("dragenter", (e) => { if ([...e.dataTransfer.types].includes("Files")) { e.preventDefault(); depth++; box.classList.add("dropping"); } });
@@ -3287,11 +3639,11 @@
3287
3639
  box.addEventListener("dragleave", () => { if (--depth <= 0) { depth = 0; box.classList.remove("dropping"); } });
3288
3640
  box.addEventListener("drop", (e) => {
3289
3641
  e.preventDefault(); depth = 0; box.classList.remove("dropping");
3290
- sendPhoto([...e.dataTransfer.files].find((f) => f.type.startsWith("image/")));
3642
+ sendFile([...e.dataTransfer.files].find((f) => /^(image|video)\//.test(f.type)));
3291
3643
  });
3292
3644
  $("chat-text").addEventListener("paste", (e) => {
3293
- const f = [...(e.clipboardData?.files || [])].find((x) => x.type.startsWith("image/"));
3294
- if (f) { e.preventDefault(); sendPhoto(f); }
3645
+ const f = [...(e.clipboardData?.files || [])].find((x) => /^(image|video)\//.test(x.type));
3646
+ if (f) { e.preventDefault(); sendFile(f); }
3295
3647
  });
3296
3648
  }
3297
3649
 
@@ -3620,7 +3972,7 @@
3620
3972
  $("rail-zone").addEventListener("mouseenter", () => peek(true));
3621
3973
  document.querySelector(".rail").addEventListener("mouseleave", () => peek(false));
3622
3974
  $("soundboard-btn").addEventListener("click", () => play("gn-179")); // the soundboard: in the side bar, not the game list
3623
- for (const id of ["home-apps", "gotd"]) $(id).addEventListener("click", (e) => { const b = e.target.closest("[data-id]"); if (b) play(b.dataset.id); });
3975
+ for (const id of ["gotd"]) $(id).addEventListener("click", (e) => { const b = e.target.closest("[data-id]"); if (b) play(b.dataset.id); });
3624
3976
  startClock();
3625
3977
  startGamepad();
3626
3978
  setPerRow(store.get(PER_ROW_KEY, 6));
@@ -3636,6 +3988,7 @@
3636
3988
  bindAdmin();
3637
3989
  bindChatTools();
3638
3990
  bindChatExtras();
3991
+ bindChatMedia();
3639
3992
  bindPolls();
3640
3993
  bindQuotes();
3641
3994
  bindAi();
@@ -3678,7 +4031,6 @@
3678
4031
  renderRecent();
3679
4032
  renderGrid();
3680
4033
  startMarquee();
3681
- renderHomeApps();
3682
4034
  renderGameOfDay();
3683
4035
  startCommunity();
3684
4036
  route();