@ywkrlerche/richardwho 1.0.39 → 1.0.41
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 +417 -60
- package/games/soundboard/button.png +0 -0
- package/games/soundboard/button_pressed.png +0 -0
- package/games/soundboard/index.html +71 -0
- package/games/soundboard/main.js +356 -0
- package/games/soundboard/sounds/kawhi-laugh.mp3 +0 -0
- package/games/soundboard/sounds/kawhi-laughs.mp3 +0 -0
- package/games/soundboard/sounds.js +9013 -0
- package/games/soundboard/style.css +352 -0
- package/games.json +1 -1
- package/index.html +40 -16
- package/package.json +1 -1
- package/style.css +93 -28
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):
|
|
290
|
-
|
|
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
|
-
|
|
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(
|
|
301
|
-
root.classList.toggle("
|
|
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
|
|
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,11 @@
|
|
|
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.41", date: "2026-11-03",
|
|
840
|
+
new: [], fixes: ["Fixed the page turning white after a while (mostly on Chromebooks), like in the chat"] },
|
|
841
|
+
{ version: "1.0.40", date: "2026-10-30",
|
|
842
|
+
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"],
|
|
843
|
+
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
844
|
{ version: "1.0.39", date: "2026-10-29",
|
|
688
845
|
fixes: ["Old daily challenge scores clean themselves up after 2 days"] },
|
|
689
846
|
{ version: "1.0.38", date: "2026-10-29",
|
|
@@ -1366,7 +1523,7 @@
|
|
|
1366
1523
|
}
|
|
1367
1524
|
async function sweepOldMessages(db) {
|
|
1368
1525
|
const dayAgo = Date.now() - 86400000;
|
|
1369
|
-
for (const path of ["chat/messages"]) {
|
|
1526
|
+
for (const path of ["chat/messages", "chat/media"]) {
|
|
1370
1527
|
try {
|
|
1371
1528
|
const old = await db.ref(path).orderByChild("ts").endAt(dayAgo).limitToFirst(200).once("value");
|
|
1372
1529
|
const changes = {};
|
|
@@ -1418,23 +1575,26 @@
|
|
|
1418
1575
|
}
|
|
1419
1576
|
|
|
1420
1577
|
// 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
1578
|
function renderMessage(key, m) {
|
|
1423
1579
|
if (!m || typeof m.name !== "string") return null;
|
|
1424
1580
|
let body;
|
|
1425
1581
|
if (typeof m.text === "string") {
|
|
1426
1582
|
// mask again on display, so words added to the owner's list later get hidden in old messages too
|
|
1427
1583
|
body = escapeHtml(maskText(m.text)).replace(/(^|\s)@([\w-]{2,16})/g, '$1<span class="at">@$2</span>');
|
|
1428
|
-
} else if (typeof m.sticker === "string" &&
|
|
1429
|
-
body = `<
|
|
1584
|
+
} else if (typeof m.sticker === "string" && /^[0-9a-f]{2,6}(_[0-9a-f]{2,6})*$/.test(m.sticker)) {
|
|
1585
|
+
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
|
|
1586
|
+
} else if (typeof m.img === "string" && /^data:image\/(webp|jpeg);base64,[A-Za-z0-9+/=]+$/.test(m.img)) {
|
|
1430
1587
|
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
1588
|
} else if (m.poll && typeof m.poll.q === "string" && pollOptions(m.poll).length >= 2) {
|
|
1432
1589
|
body = pollHtml(key, m.poll);
|
|
1590
|
+
} else if (m.media && (m.media.kind === "video" || m.media.kind === "voice") && typeof m.media.id === "string") {
|
|
1591
|
+
body = mediaHtml(m);
|
|
1433
1592
|
} else return null;
|
|
1434
1593
|
const t = new Date(m.ts || Date.now());
|
|
1435
1594
|
const div = document.createElement("div");
|
|
1436
1595
|
const mine = m.uid === chat.uid;
|
|
1437
1596
|
div.className = "chat-msg" + (mine ? " me" : "") + (m.img ? " photo" : "") + (m.sticker ? " sticker" : "") + (m.poll ? " has-poll" : "");
|
|
1597
|
+
if (m.media) div.dataset.media = m.media.id;
|
|
1438
1598
|
if (m.poll) div.pollData = m.poll; // kept so the bars can be redrawn as votes come in
|
|
1439
1599
|
div.dataset.key = key;
|
|
1440
1600
|
div.dataset.uid = m.uid || "";
|
|
@@ -1533,7 +1693,7 @@
|
|
|
1533
1693
|
function slowSeconds() { return chat.admin ? 0 : Number(chat.settings.slowMode) || 0; } // no cooldown unless the owner turns on slow mode
|
|
1534
1694
|
function updateChatStatus() {
|
|
1535
1695
|
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; });
|
|
1696
|
+
["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
1697
|
const slow = Number(chat.settings.slowMode) || 0;
|
|
1538
1698
|
$("chat-status").textContent = why || (chat.settings.locked ? "🔒 Chat is locked (only you can post)" : slow ? `🐢 Slow mode: one message every ${slow}s` : "");
|
|
1539
1699
|
$("chat-status").classList.toggle("err", !!why);
|
|
@@ -1549,7 +1709,10 @@
|
|
|
1549
1709
|
return n.error || n.name.toLowerCase() === ADMIN_NAME.toLowerCase() ? null : n.name;
|
|
1550
1710
|
}
|
|
1551
1711
|
function startTypingWatch(db) {
|
|
1552
|
-
|
|
1712
|
+
if (!typing.offsetWatched) { // once: this runs again on every reconnect and room switch
|
|
1713
|
+
typing.offsetWatched = true;
|
|
1714
|
+
db.ref(".info/serverTimeOffset").on("value", (s) => { typing.offset = s.val() || 0; });
|
|
1715
|
+
}
|
|
1553
1716
|
typing.watchRef?.off();
|
|
1554
1717
|
typing.others = {};
|
|
1555
1718
|
typing.watchRef = db.ref(roomPath("typing"));
|
|
@@ -1610,6 +1773,7 @@
|
|
|
1610
1773
|
const row = btn.closest(".chat-msg");
|
|
1611
1774
|
const act = btn.dataset.act, uid = row.dataset.uid, name = row.dataset.name, key = row.dataset.key;
|
|
1612
1775
|
if (act === "view") { openPhoto(row.querySelector("img").src); return; }
|
|
1776
|
+
if (act === "play-media") { playMedia(btn, btn.classList.contains("chat-voice") ? "voice" : "video"); return; }
|
|
1613
1777
|
if (act === "vote") {
|
|
1614
1778
|
if (!chat.uid) return;
|
|
1615
1779
|
const i = Number(btn.dataset.i), mineNow = (chat.votes[key] || {})[chat.uid];
|
|
@@ -1624,7 +1788,7 @@
|
|
|
1624
1788
|
await db.ref(`chat/flags/${key}/${chat.uid}`).set(true);
|
|
1625
1789
|
chatNote(`Reported. Messages with ${HIDE_AFTER_REPORTS} reports are hidden until the owner looks at them.`);
|
|
1626
1790
|
} else if (act === "delete" && (mine || chat.admin)) {
|
|
1627
|
-
await db.ref().update({ [roomPath(`messages/${key}`)]: null });
|
|
1791
|
+
await db.ref().update({ [roomPath(`messages/${key}`)]: null, ...(row.dataset.media ? { [`chat/media/${row.dataset.media}`]: null } : {}) });
|
|
1628
1792
|
} else if (!chat.admin || mine) {
|
|
1629
1793
|
return;
|
|
1630
1794
|
} else if (act === "purge") {
|
|
@@ -1927,7 +2091,7 @@
|
|
|
1927
2091
|
});
|
|
1928
2092
|
$("admin-clear").addEventListener("click", async () => {
|
|
1929
2093
|
if (!chat.admin || !confirm("Delete every chat message for everyone?")) return;
|
|
1930
|
-
try { await (await getFirebase()).database().ref("chat/messages")
|
|
2094
|
+
try { await (await getFirebase()).database().ref().update({ "chat/messages": null, "chat/media": null }); }
|
|
1931
2095
|
catch { alert("Couldn't clear the chat."); }
|
|
1932
2096
|
});
|
|
1933
2097
|
}
|
|
@@ -3110,19 +3274,7 @@
|
|
|
3110
3274
|
side(!phone() && store.get("rug-ai-side", true));
|
|
3111
3275
|
}
|
|
3112
3276
|
|
|
3113
|
-
// ---------- Emoji picker
|
|
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);
|
|
3277
|
+
// ---------- Emoji picker ----------
|
|
3126
3278
|
const EMOJI_GROUPS = [
|
|
3127
3279
|
["😀", "😀😃😄😁😆😅😂🤣🥲😊😇🙂🙃😉😌😍🥰😘😋😛😜🤪😝🤑🤗🤭🤫🤔🤐🤨😐😑😶😏😒🙄😬😮💨🤥😴🤤😪😮😯😲🥱😳🥺😢😭😤😠😡🤯😱😨😰🥶🥵😵💫🤠🥳😎🤓🧐😈👻💀☠️🤡💩🤖👽"],
|
|
3128
3280
|
["👍", "👍👎👏🙌👐🤝🙏✌️🤞🤟🤘👌🤌🤏👈👉👆👇☝️✋🤚🖐️👋🤙💪🫡🫶"],
|
|
@@ -3133,22 +3285,16 @@
|
|
|
3133
3285
|
];
|
|
3134
3286
|
function buildPicker() {
|
|
3135
3287
|
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>`;
|
|
3288
|
+
$("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
3289
|
const showTab = (tab) => {
|
|
3139
3290
|
$("picker-tabs").querySelectorAll("[data-tab]").forEach((b) => b.setAttribute("aria-selected", b.dataset.tab === String(tab)));
|
|
3140
|
-
$("picker-grid").
|
|
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("");
|
|
3291
|
+
$("picker-grid").innerHTML = seg(EMOJI_GROUPS[tab][1]).map((e) => `<button type="button" data-emoji="${e}">${e}</button>`).join("");
|
|
3145
3292
|
};
|
|
3146
3293
|
showTab(0);
|
|
3147
|
-
$("picker-tabs").addEventListener("click", (e) => { const b = e.target.closest("[data-tab]"); if (b) showTab(
|
|
3294
|
+
$("picker-tabs").addEventListener("click", (e) => { const b = e.target.closest("[data-tab]"); if (b) showTab(Number(b.dataset.tab)); });
|
|
3148
3295
|
$("picker-grid").addEventListener("click", async (e) => {
|
|
3149
|
-
const em = e.target.closest("[data-emoji]")
|
|
3296
|
+
const em = e.target.closest("[data-emoji]");
|
|
3150
3297
|
if (em) insertAtCursor($("chat-text"), em.dataset.emoji);
|
|
3151
|
-
if (st && await postMessage({ sticker: st.dataset.sticker })) togglePicker(false);
|
|
3152
3298
|
});
|
|
3153
3299
|
}
|
|
3154
3300
|
function insertAtCursor(input, text) {
|
|
@@ -3164,6 +3310,212 @@
|
|
|
3164
3310
|
$("emoji-btn").setAttribute("aria-expanded", open);
|
|
3165
3311
|
}
|
|
3166
3312
|
|
|
3313
|
+
// ---------- Videos and voice notes in chat ----------
|
|
3314
|
+
// A clip is re-recorded small (videos: 15 s max, 360 px, ~300 kbps; voice: 60 s max, 24 kbps) and stored at
|
|
3315
|
+
// chat/media/<id>; the chat message only carries a little preview picture and the length, so nobody downloads
|
|
3316
|
+
// a clip until they press play. Videos get the same nude check as photos, on a few frames.
|
|
3317
|
+
const VIDEO_MAX = 15, VOICE_MAX = 60, MEDIA_MAX_CHARS = 1000000;
|
|
3318
|
+
const recMime = (kind) => (kind === "video"
|
|
3319
|
+
? ["video/webm;codecs=vp8,opus", "video/webm", "video/mp4"] : ["audio/webm;codecs=opus", "audio/webm", "audio/ogg", "audio/mp4"])
|
|
3320
|
+
.find((t) => window.MediaRecorder && MediaRecorder.isTypeSupported(t)) || "";
|
|
3321
|
+
const blobToDataUrl = (blob) => new Promise((ok, fail) => { const r = new FileReader(); r.onload = () => ok(r.result); r.onerror = fail; r.readAsDataURL(blob); });
|
|
3322
|
+
const fmtSecs = (s) => `${Math.floor(s / 60)}:${String(Math.floor(s % 60)).padStart(2, "0")}`;
|
|
3323
|
+
// Records a stream until stop() or the time limit; resolves with the recorded Blob
|
|
3324
|
+
function recordStream(stream, kind, maxSecs, onTick) {
|
|
3325
|
+
const rec = new MediaRecorder(stream, { mimeType: recMime(kind), videoBitsPerSecond: 280000, audioBitsPerSecond: kind === "video" ? 32000 : 24000 });
|
|
3326
|
+
const parts = [], started = Date.now();
|
|
3327
|
+
rec.ondataavailable = (e) => { if (e.data.size) parts.push(e.data); };
|
|
3328
|
+
const done = new Promise((ok) => { rec.onstop = () => ok(new Blob(parts, { type: rec.mimeType.split(";")[0] })); });
|
|
3329
|
+
const tick = setInterval(() => {
|
|
3330
|
+
const secs = (Date.now() - started) / 1000;
|
|
3331
|
+
onTick?.(secs);
|
|
3332
|
+
if (secs >= maxSecs && rec.state === "recording") rec.stop();
|
|
3333
|
+
}, 200);
|
|
3334
|
+
rec.start(1000);
|
|
3335
|
+
return { done: done.finally(() => clearInterval(tick)), stop: () => { if (rec.state === "recording") rec.stop(); }, started };
|
|
3336
|
+
}
|
|
3337
|
+
// A video file from the computer: played into a small canvas (and its sound into a recorder), first 15 s only
|
|
3338
|
+
async function shrinkVideoFile(file, onTick) {
|
|
3339
|
+
const v = document.createElement("video");
|
|
3340
|
+
v.src = URL.createObjectURL(file);
|
|
3341
|
+
v.playsInline = true;
|
|
3342
|
+
await new Promise((ok, fail) => { v.onloadedmetadata = ok; v.onerror = () => fail(new Error("unreadable")); });
|
|
3343
|
+
const k = Math.min(1, 360 / Math.max(v.videoWidth, v.videoHeight));
|
|
3344
|
+
const c = document.createElement("canvas");
|
|
3345
|
+
c.width = Math.round(v.videoWidth * k / 2) * 2; c.height = Math.round(v.videoHeight * k / 2) * 2;
|
|
3346
|
+
const g = c.getContext("2d");
|
|
3347
|
+
const ac = new AudioContext(), out = ac.createMediaStreamDestination();
|
|
3348
|
+
ac.createMediaElementSource(v).connect(out); // the sound goes to the recording, not the speakers
|
|
3349
|
+
const stream = new MediaStream([...c.captureStream(24).getVideoTracks(), ...out.stream.getAudioTracks()]);
|
|
3350
|
+
let raf = 0;
|
|
3351
|
+
const draw = () => { g.drawImage(v, 0, 0, c.width, c.height); raf = requestAnimationFrame(draw); };
|
|
3352
|
+
await v.play();
|
|
3353
|
+
draw();
|
|
3354
|
+
const r = recordStream(stream, "video", Math.min(VIDEO_MAX, v.duration || VIDEO_MAX), onTick);
|
|
3355
|
+
v.onended = () => r.stop();
|
|
3356
|
+
const blob = await r.done;
|
|
3357
|
+
cancelAnimationFrame(raf); v.pause(); ac.close(); URL.revokeObjectURL(v.src);
|
|
3358
|
+
return { blob, secs: Math.min(VIDEO_MAX, v.duration || VIDEO_MAX), longer: (v.duration || 0) > VIDEO_MAX + 0.5 };
|
|
3359
|
+
}
|
|
3360
|
+
// Grabs a few frames of a recorded video: a preview picture, and (for the nude check) frames to classify
|
|
3361
|
+
async function videoFrames(blob) {
|
|
3362
|
+
const v = document.createElement("video");
|
|
3363
|
+
v.src = URL.createObjectURL(blob); v.muted = true; v.playsInline = true;
|
|
3364
|
+
await new Promise((ok, fail) => { v.onloadeddata = ok; v.onerror = () => fail(new Error("unreadable")); });
|
|
3365
|
+
// recorded WebM often reports no length until it's been read to the end
|
|
3366
|
+
if (!isFinite(v.duration)) { v.currentTime = 1e9; await new Promise((ok) => { v.ontimeupdate = () => { v.ontimeupdate = null; ok(); }; }); }
|
|
3367
|
+
const len = isFinite(v.duration) ? v.duration : 1;
|
|
3368
|
+
const grab = async (t, side) => {
|
|
3369
|
+
v.currentTime = Math.min(len - 0.05, Math.max(0, t));
|
|
3370
|
+
await new Promise((ok) => { v.onseeked = ok; });
|
|
3371
|
+
const k = side / Math.max(v.videoWidth, v.videoHeight), c = document.createElement("canvas");
|
|
3372
|
+
c.width = Math.max(1, Math.round(v.videoWidth * k)); c.height = Math.max(1, Math.round(v.videoHeight * k));
|
|
3373
|
+
c.getContext("2d").drawImage(v, 0, 0, c.width, c.height);
|
|
3374
|
+
return c;
|
|
3375
|
+
};
|
|
3376
|
+
const frames = [];
|
|
3377
|
+
for (const f of [0.15, 0.5, 0.85]) frames.push(await grab(len * f, 224));
|
|
3378
|
+
const poster = (await grab(len * 0.15, 240)).toDataURL("image/jpeg", 0.6);
|
|
3379
|
+
URL.revokeObjectURL(v.src);
|
|
3380
|
+
return { frames, poster, secs: len };
|
|
3381
|
+
}
|
|
3382
|
+
async function videoIsOk(frames) {
|
|
3383
|
+
const model = await loadNsfw();
|
|
3384
|
+
for (const c of frames) {
|
|
3385
|
+
const sq = document.createElement("canvas"); sq.width = sq.height = 224;
|
|
3386
|
+
sq.getContext("2d").drawImage(c, 0, 0, 224, 224);
|
|
3387
|
+
const p = Object.fromEntries((await model.classify(sq)).map((x) => [x.className, x.probability]));
|
|
3388
|
+
if ((p.Porn || 0) > 0.35 || (p.Hentai || 0) > 0.35 || (p.Sexy || 0) > 0.6) return false;
|
|
3389
|
+
}
|
|
3390
|
+
return true;
|
|
3391
|
+
}
|
|
3392
|
+
// Posts a clip: the data first (its own write), then the chat message that points to it
|
|
3393
|
+
async function postMedia(kind, blob, secs, poster) {
|
|
3394
|
+
const data = await blobToDataUrl(blob);
|
|
3395
|
+
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; }
|
|
3396
|
+
const app = await getFirebase();
|
|
3397
|
+
if (!app || !chat.uid || !chatSender()) return false;
|
|
3398
|
+
const db = app.database(), TS = window.firebase.database.ServerValue.TIMESTAMP;
|
|
3399
|
+
const id = db.ref("chat/media").push().key;
|
|
3400
|
+
try {
|
|
3401
|
+
await db.ref().update({ [`chat/media/${id}`]: { data, uid: chat.uid, ts: TS }, [`chat/mediaLast/${chat.uid}`]: TS });
|
|
3402
|
+
} catch {
|
|
3403
|
+
chatNote(blockedReason() || "Wait a few seconds between videos and voice notes.", true);
|
|
3404
|
+
return false;
|
|
3405
|
+
}
|
|
3406
|
+
return postMessage({ media: { kind, id, secs: Math.max(1, Math.round(secs)), ...(poster && poster.length <= 14000 ? { poster } : {}) } });
|
|
3407
|
+
}
|
|
3408
|
+
async function sendVideoFile(file) {
|
|
3409
|
+
if (!file || !/^video\//.test(file.type)) { chatNote("That isn't a video.", true); return; }
|
|
3410
|
+
if (file.size > 300 * 1048576) { chatNote("That video is too big (300 MB max).", true); return; }
|
|
3411
|
+
if (!recMime("video")) { chatNote("This browser can't send videos.", true); return; }
|
|
3412
|
+
if (!chatSender()) return;
|
|
3413
|
+
$("photo-btn").disabled = true;
|
|
3414
|
+
try {
|
|
3415
|
+
chatNote("Getting the video ready…");
|
|
3416
|
+
const { blob, longer } = await shrinkVideoFile(file, (s) => chatNote(`Getting the video ready… ${Math.floor(s)}s of ${VIDEO_MAX}s max`));
|
|
3417
|
+
chatNote("Checking video…");
|
|
3418
|
+
const { frames, poster, secs } = await videoFrames(blob);
|
|
3419
|
+
if (!(await videoIsOk(frames))) { chatNote("That video can't be sent here.", true); return; }
|
|
3420
|
+
if (await postMedia("video", blob, secs, poster)) chatNote(longer ? `Sent the first ${VIDEO_MAX} seconds.` : "");
|
|
3421
|
+
} catch {
|
|
3422
|
+
chatNote("Couldn't use that video. Try a different one.", true);
|
|
3423
|
+
} finally {
|
|
3424
|
+
$("photo-btn").disabled = !!blockedReason();
|
|
3425
|
+
$("photo-input").value = "";
|
|
3426
|
+
}
|
|
3427
|
+
}
|
|
3428
|
+
// 📸 window, video mode: record up to 15 s with sound, preview, then send
|
|
3429
|
+
let camRec = null, camClip = null;
|
|
3430
|
+
async function recordCamVideo() {
|
|
3431
|
+
if (camRec) { camRec.stop(); return; }
|
|
3432
|
+
if (!recMime("video")) { $("cam-msg").textContent = "This browser can't record video."; return; }
|
|
3433
|
+
try {
|
|
3434
|
+
const mic = await navigator.mediaDevices.getUserMedia({ audio: true });
|
|
3435
|
+
const stream = new MediaStream([...camStream.getVideoTracks(), ...mic.getAudioTracks()]);
|
|
3436
|
+
$("cam-rec").textContent = "■ Stop";
|
|
3437
|
+
$("cam-snap").hidden = true;
|
|
3438
|
+
camRec = recordStream(stream, "video", VIDEO_MAX, (s) => { $("cam-msg").textContent = `Recording ${fmtSecs(s)} / ${fmtSecs(VIDEO_MAX)}`; });
|
|
3439
|
+
const blob = await camRec.done;
|
|
3440
|
+
mic.getTracks().forEach((t) => t.stop());
|
|
3441
|
+
camRec = null;
|
|
3442
|
+
camClip = blob;
|
|
3443
|
+
$("cam-video").hidden = true;
|
|
3444
|
+
$("cam-clip").hidden = false;
|
|
3445
|
+
$("cam-clip").src = URL.createObjectURL(blob);
|
|
3446
|
+
$("cam-msg").textContent = "";
|
|
3447
|
+
$("cam-rec").hidden = true; $("cam-retake").hidden = false; $("cam-send").hidden = false;
|
|
3448
|
+
$("cam-rec").textContent = "● Record video";
|
|
3449
|
+
} catch {
|
|
3450
|
+
camRec = null;
|
|
3451
|
+
$("cam-msg").textContent = "Couldn't use your microphone. Allow it in the browser and try again.";
|
|
3452
|
+
}
|
|
3453
|
+
}
|
|
3454
|
+
async function sendCamClip() {
|
|
3455
|
+
const blob = camClip;
|
|
3456
|
+
closeCamera();
|
|
3457
|
+
if (!blob) return;
|
|
3458
|
+
try {
|
|
3459
|
+
chatNote("Checking video…");
|
|
3460
|
+
const { frames, poster, secs } = await videoFrames(blob);
|
|
3461
|
+
if (!(await videoIsOk(frames))) { chatNote("That video can't be sent here.", true); return; }
|
|
3462
|
+
if (await postMedia("video", blob, secs, poster)) chatNote("");
|
|
3463
|
+
} catch { chatNote("Couldn't send that video.", true); }
|
|
3464
|
+
}
|
|
3465
|
+
// 🎤 voice notes: press to record (60 s max), then Send or Cancel
|
|
3466
|
+
let voiceRec = null, voiceMic = null;
|
|
3467
|
+
async function startVoice() {
|
|
3468
|
+
if (voiceRec || !chatSender()) return;
|
|
3469
|
+
if (!recMime("voice")) { chatNote("This browser can't record voice notes.", true); return; }
|
|
3470
|
+
try { voiceMic = await navigator.mediaDevices.getUserMedia({ audio: true }); }
|
|
3471
|
+
catch { chatNote("Couldn't use your microphone. Allow it in the browser and try again.", true); return; }
|
|
3472
|
+
$("voice-bar").hidden = false;
|
|
3473
|
+
voiceRec = recordStream(voiceMic, "voice", VOICE_MAX, (s) => { $("voice-time").textContent = `${fmtSecs(s)} / ${fmtSecs(VOICE_MAX)}`; });
|
|
3474
|
+
voiceRec.done.then((blob) => { voiceRec.blob = blob; });
|
|
3475
|
+
}
|
|
3476
|
+
async function finishVoice(send) {
|
|
3477
|
+
if (!voiceRec) return;
|
|
3478
|
+
const r = voiceRec;
|
|
3479
|
+
r.stop();
|
|
3480
|
+
const blob = await r.done;
|
|
3481
|
+
voiceMic?.getTracks().forEach((t) => t.stop());
|
|
3482
|
+
voiceRec = voiceMic = null;
|
|
3483
|
+
$("voice-bar").hidden = true;
|
|
3484
|
+
$("voice-time").textContent = "0:00";
|
|
3485
|
+
const secs = (Date.now() - r.started) / 1000;
|
|
3486
|
+
if (send && secs >= 1 && await postMedia("voice", blob, Math.min(secs, VOICE_MAX))) chatNote("");
|
|
3487
|
+
}
|
|
3488
|
+
// A clip in the chat: a play card; the clip itself is fetched the first time someone presses play
|
|
3489
|
+
function mediaHtml(m) {
|
|
3490
|
+
const md = m.media, secs = fmtSecs(Number(md.secs) || 0);
|
|
3491
|
+
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>`;
|
|
3492
|
+
const poster = typeof md.poster === "string" && /^data:image\/(jpeg|webp);base64,[A-Za-z0-9+/=]+$/.test(md.poster) ? md.poster : "";
|
|
3493
|
+
return `<button class="chat-video" type="button" data-act="play-media" data-media="${escapeHtml(md.id)}">` +
|
|
3494
|
+
`${poster ? `<img src="${poster}" alt="">` : ""}<span class="chat-video-play">▶</span><span class="chat-media-len">${secs}</span></button>`;
|
|
3495
|
+
}
|
|
3496
|
+
async function playMedia(btn, kind) {
|
|
3497
|
+
btn.disabled = true;
|
|
3498
|
+
try {
|
|
3499
|
+
const snap = await (await getFirebase()).database().ref(`chat/media/${btn.dataset.media}`).once("value");
|
|
3500
|
+
const data = snap.val()?.data;
|
|
3501
|
+
if (typeof data !== "string" || !/^data:(video|audio)\/(webm|mp4|ogg)/.test(data)) throw new Error("gone");
|
|
3502
|
+
const el = document.createElement(kind === "voice" ? "audio" : "video");
|
|
3503
|
+
el.className = kind === "voice" ? "chat-voice-player" : "chat-video-player";
|
|
3504
|
+
el.src = data; el.controls = true; el.autoplay = true; el.playsInline = true;
|
|
3505
|
+
el.controlsList = "nodownload"; // play in the chat; no download button
|
|
3506
|
+
btn.replaceWith(el);
|
|
3507
|
+
} catch {
|
|
3508
|
+
btn.disabled = false;
|
|
3509
|
+
btn.querySelector(".chat-media-len").textContent = "unavailable";
|
|
3510
|
+
}
|
|
3511
|
+
}
|
|
3512
|
+
function bindChatMedia() {
|
|
3513
|
+
$("voice-btn").addEventListener("click", startVoice);
|
|
3514
|
+
$("voice-send").addEventListener("click", () => finishVoice(true));
|
|
3515
|
+
$("voice-cancel").addEventListener("click", () => finishVoice(false));
|
|
3516
|
+
$("cam-rec").addEventListener("click", recordCamVideo);
|
|
3517
|
+
}
|
|
3518
|
+
|
|
3167
3519
|
// ---------- Photos: drag and drop, paste, or 📷 ----------
|
|
3168
3520
|
// Posted straight away (no review). Before sending, a nudity detector (NSFW.js, runs in this browser)
|
|
3169
3521
|
// checks the picture; the photo is re-drawn, which also strips hidden data like location, and shrunk to ≤ ~100 KB.
|
|
@@ -3241,8 +3593,9 @@
|
|
|
3241
3593
|
}
|
|
3242
3594
|
}
|
|
3243
3595
|
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;
|
|
3596
|
+
$("cam-video").hidden = taken; $("cam-shot").hidden = !taken; $("cam-clip").hidden = true;
|
|
3597
|
+
$("cam-snap").hidden = taken; $("cam-rec").hidden = taken; $("cam-retake").hidden = !taken; $("cam-send").hidden = !taken;
|
|
3598
|
+
camClip = null;
|
|
3246
3599
|
}
|
|
3247
3600
|
function snapCamera() {
|
|
3248
3601
|
const v = $("cam-video"), c = $("cam-shot");
|
|
@@ -3254,6 +3607,9 @@
|
|
|
3254
3607
|
showCamShot(true);
|
|
3255
3608
|
}
|
|
3256
3609
|
function closeCamera() {
|
|
3610
|
+
camRec?.stop();
|
|
3611
|
+
$("cam-clip").pause();
|
|
3612
|
+
$("cam-clip").removeAttribute("src");
|
|
3257
3613
|
camStream?.getTracks().forEach((t) => t.stop());
|
|
3258
3614
|
camStream = null;
|
|
3259
3615
|
$("cam-video").srcObject = null;
|
|
@@ -3269,7 +3625,7 @@
|
|
|
3269
3625
|
$("cam-btn").addEventListener("click", openCamera);
|
|
3270
3626
|
$("cam-snap").addEventListener("click", snapCamera);
|
|
3271
3627
|
$("cam-retake").addEventListener("click", () => showCamShot(false));
|
|
3272
|
-
$("cam-send").addEventListener("click", sendCamPhoto);
|
|
3628
|
+
$("cam-send").addEventListener("click", () => (camClip ? sendCamClip() : sendCamPhoto()));
|
|
3273
3629
|
$("cam-close").addEventListener("click", closeCamera);
|
|
3274
3630
|
$("cam-wrap").addEventListener("click", (e) => { if (e.target === $("cam-wrap")) closeCamera(); });
|
|
3275
3631
|
$("emoji-btn").addEventListener("click", () => togglePicker());
|
|
@@ -3279,7 +3635,8 @@
|
|
|
3279
3635
|
});
|
|
3280
3636
|
$("picker").addEventListener("keydown", (e) => { if (e.key === "Escape") { togglePicker(false); $("emoji-btn").focus(); } });
|
|
3281
3637
|
$("photo-btn").addEventListener("click", () => $("photo-input").click());
|
|
3282
|
-
|
|
3638
|
+
const sendFile = (f) => (f && f.type.startsWith("video/") ? sendVideoFile(f) : sendPhoto(f));
|
|
3639
|
+
$("photo-input").addEventListener("change", () => sendFile($("photo-input").files[0]));
|
|
3283
3640
|
const box = $("chat-box");
|
|
3284
3641
|
let depth = 0;
|
|
3285
3642
|
box.addEventListener("dragenter", (e) => { if ([...e.dataTransfer.types].includes("Files")) { e.preventDefault(); depth++; box.classList.add("dropping"); } });
|
|
@@ -3287,11 +3644,11 @@
|
|
|
3287
3644
|
box.addEventListener("dragleave", () => { if (--depth <= 0) { depth = 0; box.classList.remove("dropping"); } });
|
|
3288
3645
|
box.addEventListener("drop", (e) => {
|
|
3289
3646
|
e.preventDefault(); depth = 0; box.classList.remove("dropping");
|
|
3290
|
-
|
|
3647
|
+
sendFile([...e.dataTransfer.files].find((f) => /^(image|video)\//.test(f.type)));
|
|
3291
3648
|
});
|
|
3292
3649
|
$("chat-text").addEventListener("paste", (e) => {
|
|
3293
|
-
const f = [...(e.clipboardData?.files || [])].find((x) => x.type
|
|
3294
|
-
if (f) { e.preventDefault();
|
|
3650
|
+
const f = [...(e.clipboardData?.files || [])].find((x) => /^(image|video)\//.test(x.type));
|
|
3651
|
+
if (f) { e.preventDefault(); sendFile(f); }
|
|
3295
3652
|
});
|
|
3296
3653
|
}
|
|
3297
3654
|
|
|
@@ -3620,7 +3977,7 @@
|
|
|
3620
3977
|
$("rail-zone").addEventListener("mouseenter", () => peek(true));
|
|
3621
3978
|
document.querySelector(".rail").addEventListener("mouseleave", () => peek(false));
|
|
3622
3979
|
$("soundboard-btn").addEventListener("click", () => play("gn-179")); // the soundboard: in the side bar, not the game list
|
|
3623
|
-
for (const id of ["
|
|
3980
|
+
for (const id of ["gotd"]) $(id).addEventListener("click", (e) => { const b = e.target.closest("[data-id]"); if (b) play(b.dataset.id); });
|
|
3624
3981
|
startClock();
|
|
3625
3982
|
startGamepad();
|
|
3626
3983
|
setPerRow(store.get(PER_ROW_KEY, 6));
|
|
@@ -3636,6 +3993,7 @@
|
|
|
3636
3993
|
bindAdmin();
|
|
3637
3994
|
bindChatTools();
|
|
3638
3995
|
bindChatExtras();
|
|
3996
|
+
bindChatMedia();
|
|
3639
3997
|
bindPolls();
|
|
3640
3998
|
bindQuotes();
|
|
3641
3999
|
bindAi();
|
|
@@ -3678,7 +4036,6 @@
|
|
|
3678
4036
|
renderRecent();
|
|
3679
4037
|
renderGrid();
|
|
3680
4038
|
startMarquee();
|
|
3681
|
-
renderHomeApps();
|
|
3682
4039
|
renderGameOfDay();
|
|
3683
4040
|
startCommunity();
|
|
3684
4041
|
route();
|