-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathapp.js
More file actions
456 lines (428 loc) · 17.9 KB
/
Copy pathapp.js
File metadata and controls
456 lines (428 loc) · 17.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
/* Wolfy Update Tracker — live tally, odds board, Ban Risk Multiplier(TM).
Data source: public GitHub issues + reactions on this repo. No backend, no auth.
Conditional requests (ETag) are used so repeated polling is cheap. */
const API = `https://api.github.com/repos/${CONFIG.repoOwner}/${CONFIG.repoName}`;
const $ = (id) => document.getElementById(id);
const START = new Date(CONFIG.trackingStart);
const END = new Date(CONFIG.trackingEnd);
const HOUR = 3600e3;
const etags = new Map(); // url -> etag (in-memory; 304s don't burn rate limit)
async function gh(url) {
const headers = { Accept: "application/vnd.github+json" };
if (etags.has(url)) headers["If-None-Match"] = etags.get(url);
const res = await fetch(url, { headers });
if (res.status === 304 && ghCache.has(url)) return ghCache.get(url);
if (!res.ok) {
if (res.status === 403) throw new Error("rate-limited");
throw new Error(`GitHub API ${res.status}`);
}
const etag = res.headers.get("ETag");
if (etag) etags.set(url, etag);
const data = await res.json();
ghCache.set(url, data);
return data;
}
const ghCache = new Map();
/* ---------- links ---------- */
const newIssueBase = `https://github.com/${CONFIG.repoOwner}/${CONFIG.repoName}/issues/new`;
$("reportBtn").href = `${newIssueBase}?template=sighting.yml`;
$("omenBtn").href = `${newIssueBase}?template=mod-omen.yml`;
$("repoLink").href = CONFIG.repoUrl;
$("oddsLink").href = `${CONFIG.repoUrl}/issues?q=label%3Aodds`;
/* ---------- parsing helpers ---------- */
// Issue-form bodies render as "### Label\n\nvalue\n\n### Next label..."
function fieldValue(body, labelStart) {
if (!body) return "";
const re = new RegExp(`###\\s*${labelStart}[^\\n]*\\n([\\s\\S]*?)(?=\\n###|$)`, "i");
const m = body.match(re);
return m ? m[1].trim() : "";
}
function firstInt(text, fallback) {
const m = (text || "").match(/\d+/);
return m ? parseInt(m[0], 10) : fallback;
}
function esc(s) {
return (s || "").replace(/[&<>"']/g, (c) =>
({ "&": "&", "<": "<", ">": ">", '"': """, "'": "'" }[c]));
}
/* ---------- tracked phrases (keywords.json is the source of truth) ---------- */
// Fallback mirror of ../keywords.json if the file can't be fetched.
const DEFAULT_KEYWORDS = ["update", "updates", "proceed", "any progress", "build new apk please"];
let KEYWORDS = DEFAULT_KEYWORDS;
const escRe = (s) => s.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
const kwRe = (kw) => new RegExp(
"\\b" + kw.trim().split(/\s+/).map(escRe).join("\\s+") + "\\b", "gi");
// Case-insensitive occurrences of all tracked phrases in text.
function phraseOccurrences(text) {
const t = text || "";
return KEYWORDS.reduce((n, kw) => n + ((t.match(kwRe(kw)) || []).length), 0);
}
// Speaker attribution: transcript lines/blocks attributed to another speaker
// don't count as Wolfy utterances (Discord paste "Name — HH.MM" blocks,
// inline "Name: msg" prefixes). Unattributed text counts — the sighting form
// asks for Wolfy's verbatim words.
const SPEAKER_HDR = /^[ \t]*([A-Za-z0-9_.\- ]{1,30}?)[ \t]*\u2014[ \t]*\d{1,2}[:.]\d{2}(?::\d{2})?[ \t]*(?:[ap]m)?[ \t]*$/gim;
const NAME_PREFIX = /^[ \t]*([A-Za-z][A-Za-z0-9_.\-]{0,29}):/;
const isWolfy = (n) => /wolfy/i.test(n || "");
function wolfyText(quote) {
const t = quote || "";
let keep = "", pos = 0, cur = true, m;
SPEAKER_HDR.lastIndex = 0;
while ((m = SPEAKER_HDR.exec(t))) {
if (cur) keep += t.slice(pos, m.index);
cur = isWolfy(m[1]);
pos = m.index + m[0].length;
}
if (cur) keep += t.slice(pos);
return keep.split("\n")
.filter((ln) => { const p = ln.match(NAME_PREFIX); return !p || isWolfy(p[1]); })
.join("\n");
}
async function loadKeywords() {
try {
const res = await fetch("keywords.json", { cache: "no-store" });
if (res.ok) {
const kws = (await res.json()).filter((k) => typeof k === "string" && k.trim());
if (kws.length) KEYWORDS = kws.map((k) => k.trim());
}
} catch { /* keep built-in defaults */ }
}
const fmtTZ = (d) =>
new Intl.DateTimeFormat("fi-FI", {
timeZone: CONFIG.timezone, day: "2-digit", month: "2-digit",
hour: "2-digit", minute: "2-digit",
}).format(d);
/* ---------- clock + countdown ---------- */
function tick() {
const now = new Date();
$("localClock").textContent = new Intl.DateTimeFormat("fi-FI", {
timeZone: CONFIG.timezone, hour: "2-digit", minute: "2-digit", second: "2-digit",
}).format(now);
const remain = END - now;
const total = END - START;
if (remain <= 0) {
$("countdown").textContent = "00:00:00";
$("progressBar").style.width = "100%";
document.title = "🐺 TIME'S UP — Wolfy Update Tracker";
} else {
const h = Math.floor(remain / HOUR);
const m = Math.floor((remain % HOUR) / 60e3);
const s = Math.floor((remain % 60e3) / 1e3);
$("countdown").textContent =
`${String(h).padStart(2, "0")}:${String(m).padStart(2, "0")}:${String(s).padStart(2, "0")}`;
$("progressBar").style.width = `${Math.min(100, ((now - START) / total) * 100)}%`;
}
}
$("startTime").textContent = fmtTZ(START) + " UTC+7";
$("endTime").textContent = fmtTZ(END) + " UTC+7";
setInterval(tick, 1000);
tick();
/* ---------- fallback snapshot (built by GitHub Actions) ---------- */
// When the visitor's IP is out of anonymous GitHub API quota, use the
// repo-hosted snapshot instead — always available since it's on Pages.
async function fetchState() {
const res = await fetch("data/state.json", { cache: "no-store" });
if (!res.ok) throw new Error("no snapshot");
return res.json();
}
/* ---------- sightings ---------- */
let lastCount = -1;
let sightings = [];
async function loadSightings() {
let source = "live";
try {
const issues = await gh(
`${API}/issues?labels=sighting&state=all&per_page=100&sort=created&direction=desc`);
sightings = issues.filter((i) => !i.pull_request)
// Rejected reports (closed as not_planned) never count, same as the
// snapshot builder — otherwise troll counts leak into the live total.
.filter((i) => !(i.state === "closed" && i.state_reason === "not_planned"))
.map((i) => {
const reported = Math.max(0, firstInt(fieldValue(i.body, "How many"), 0) || 0);
const quote = fieldValue(i.body, "What did Wolfy say").replace(/^"|"$/g, "");
return {
n: i.number,
title: i.title,
who: i.user ? i.user.login : "anonymous",
at: new Date(i.created_at),
// A quote can only raise the reported count, never lower it.
count: Math.max(1, reported, phraseOccurrences(wolfyText(quote))),
quote,
src: "issue",
};
});
// Webhook sightings recorded via repository_dispatch land in
// data/sightings.json (deployed with the site) — merge them in.
try {
const res = await fetch("data/sightings.json", { cache: "no-store" });
if (res.ok) {
const extra = (await res.json()).filter((s) => s && s.timestamp)
.map((s, idx) => ({
n: `wh-${idx}`, title: s.message, who: s.author_name || "anonymous",
at: new Date(s.timestamp),
count: Math.max(1, s.count || 0, phraseOccurrences(s.message)),
quote: s.message, src: s.source || "webhook",
}));
sightings = sightings.concat(extra)
.sort((a, b) => b.at - a.at);
}
} catch { /* no webhook log yet */ }
} catch (e) {
try {
const st = await fetchState();
sightings = st.sightings.map((s) => ({ ...s, at: new Date(s.at) }))
.sort((a, b) => b.at - a.at);
source = "snapshot";
} catch { /* leave old data */ }
}
if (!sightings.length && source !== "snapshot") {
$("feedStatus").textContent = "no sightings yet — the wolf is quiet, too quiet";
renderSightings();
return;
}
renderSightings();
const stamp = new Date().toLocaleTimeString();
$("feedStatus").textContent = source === "snapshot"
? `showing bot snapshot · ${sightings.length} sightings on record`
: `last refreshed ${stamp} · ${sightings.length} sightings on record`;
}
function renderSightings() {
const total = sightings.reduce((a, s) => a + s.count, 0);
const el = $("tickerCount");
if (lastCount >= 0 && total > lastCount) {
el.classList.remove("bump"); void el.offsetWidth; el.classList.add("bump");
confetti();
}
lastCount = total;
el.textContent = total;
// pace / projection
const now = Date.now();
const elapsedH = Math.max((now - START) / HOUR, 0.01);
const remainH = Math.max((END - now) / HOUR, 0);
const pace = total / Math.min(elapsedH, 24);
const proj = total + pace * remainH;
$("paceLine").textContent = total === 0
? "Waiting for the first “update”… the silence is deafening."
: `pace ${pace.toFixed(2)}/h → projected ${proj.toFixed(1)} updates by closing time`;
drawSparkline();
renderKuitti(total);
}
function drawSparkline() {
const c = $("sparkline");
const dpr = window.devicePixelRatio || 1;
const w = c.clientWidth || 300, h = 64;
c.width = w * dpr; c.height = h * dpr;
const ctx = c.getContext("2d");
ctx.scale(dpr, dpr);
ctx.clearRect(0, 0, w, h);
const buckets = new Array(24).fill(0);
for (const s of sightings) {
const bh = Math.floor((s.at - START) / HOUR);
if (bh >= 0 && bh < 24) buckets[bh] += s.count;
}
const max = Math.max(...buckets, 1);
const bw = w / 24;
buckets.forEach((v, i) => {
const bh = (v / max) * (h - 8);
ctx.fillStyle = v > 0 ? "#ff8c1a" : "#4a361866";
ctx.beginPath();
ctx.roundRect(i * bw + 2, h - bh, bw - 4, bh, 3);
ctx.fill();
});
}
function renderKuitti(total) {
const items = $("kuittiItems");
if (!sightings.length) {
items.innerHTML = `<div class="kuitti-empty">— ei havaintoja vielä —<br>(grillijono odottaa)</div>`;
} else {
items.innerHTML = sightings.map((s) => {
const desc = s.quote
? `"${esc(s.quote).slice(0, 60)}"`
: esc(s.title.replace(/^🐺\s*/, "").slice(0, 44));
const tag = s.src && s.src !== "issue" ? `[${esc(s.src)}] ` : "";
return `<div class="kuitti-item" title="#${s.n} by ${esc(s.who)}">
<span class="desc">${fmtTZ(s.at)} ${tag}${desc}</span>
<span class="qty">${s.count}× upd</span>
</div>`;
}).join("");
}
$("kuittiTotal").textContent =
`------------------------------
YHTEENSÄ / TOTAL: ${total} update${total === 1 ? "" : "s"}
MAKSETTU: grillikuiteilla
KIITOS JA AUKI HUOMISEEN
Tervetuloa K-Rautaan!
------------------------------`;
}
/* ---------- odds board ---------- */
const LINE_JOKES = [
"litasitko liian aikaisin?",
"koira haistaa päivityksen",
"house edge: makkaraa",
"las Vegas wishes",
"the Whaley's line",
];
async function loadOdds() {
try {
const issues = await gh(`${API}/issues?labels=odds&state=open&per_page=5`);
const board = issues.find((i) => !i.pull_request);
if (!board) { $("oddsStatus").textContent = "odds board missing — house is renovating"; return; }
$("oddsLink").href = board.html_url;
const comments = await gh(`${API}/issues/${board.number}/comments?per_page=100`);
const byLine = new Map();
for (const c of comments) {
const m = (c.body || "").match(/<!--\s*line:([\d.]+)\s*-->/);
if (m) byLine.set(parseFloat(m[1]), {
over: (c.reactions && c.reactions["+1"]) || 0,
under: (c.reactions && c.reactions["-1"]) || 0,
});
}
renderOdds(byLine);
$("oddsStatus").textContent = "odds update every minute · 👍/👎 reactions are the bets";
} catch (e) {
try {
const st = await fetchState();
if (st.board_issue)
$("oddsLink").href = `${CONFIG.repoUrl}/issues/${st.board_issue}`;
const byLine = new Map(Object.entries(st.odds || {})
.map(([k, v]) => [parseFloat(k), v]));
renderOdds(byLine);
$("oddsStatus").textContent = "showing bot snapshot odds (live API cooling down)";
} catch {
$("oddsStatus").textContent = `odds refresh hiccup (${e.message}) — bookie is at the grill`;
}
}
}
function renderOdds(byLine) {
const grid = $("oddsGrid");
let hottest = -1, hotVol = -1;
const cards = CONFIG.lines.map((line, i) => {
const c = byLine.get(line);
const over = c ? c.over : 0;
const under = c ? c.under : 0;
const sum = over + under;
if (sum > hotVol) { hotVol = sum; hottest = i; }
const op = sum ? Math.round((over / sum) * 100) : 50;
const up = 100 - op;
return { line, over, under, op, up, joke: LINE_JOKES[i % LINE_JOKES.length], sum };
});
grid.innerHTML = cards.map((c, i) => `
<div class="odds-card${i === hottest && c.sum > 0 ? " hot" : ""}">
<div class="line">O/U ${c.line} <small>updates</small></div>
<div class="split-bar">
<div class="over" style="width:${c.op}%"></div>
<div class="under" style="width:${c.up}%"></div>
</div>
<div class="pct"><span class="o">OVER ${c.op}% (${c.over})</span><span class="u">(${c.under}) ${c.up}% UNDER</span></div>
<div class="funny">${c.joke} · ${c.sum} bet${c.sum === 1 ? "" : "s"}</div>
</div>`).join("");
}
/* ---------- Ban Risk Multiplier(TM) ---------- */
function banVerdict(mult, dist, n) {
if (n === 0) return "No omens on record. Either the mods are asleep or the trap is set.";
if (dist >= 0.8) return "Code red. Wolfy is one 'update' away from becoming a cautionary tale.";
if (dist >= 0.5) return "The mods are circling like seagulls over a grill queue.";
if (dist >= 0.25) return "Mild menace detected. Mia has been seen typing, then deleting.";
return "Low-level grumbling. Statistically, Wolfy is fine. Spiritually, unclear.";
}
const VOL_LABELS = ["Flat", "Twitchy", "Spicy", "Chaotic", "Mia-tier"];
async function loadBanRisk() {
const cutoff = Date.now() - CONFIG.banWindowHours * HOUR;
try {
const issues = await gh(`${API}/issues?labels=mod-omen&state=all&per_page=100`);
const omens = issues.filter((i) => !i.pull_request && new Date(i.created_at) >= cutoff)
.map((i) => ({
n: i.number,
mod: fieldValue(i.body, "Which mod") || "a mod",
text: fieldValue(i.body, "What did they say"),
menace: Math.min(5, Math.max(1, firstInt(fieldValue(i.body, "Menace level"), 3))),
at: new Date(i.created_at),
})).sort((a, b) => b.at - a.at);
renderBanRisk(omens);
} catch (e) {
try {
const st = await fetchState();
const omens = (st.omens || [])
.map((o) => ({ ...o, at: new Date(o.at) }))
.filter((o) => o.at >= cutoff)
.sort((a, b) => b.at - a.at);
renderBanRisk(omens);
} catch {
$("banVerdict").textContent = `omen feed unreachable (${e.message}) — assuming the worst`;
}
}
}
function renderBanRisk(omens) {
const now = Date.now();
let raw = 0;
for (const o of omens) {
const ageH = (now - o.at) / HOUR;
raw += o.menace * Math.pow(0.5, ageH / CONFIG.banDecayHalfLifeH);
}
const mult = 1 + raw / 5;
const dist = Math.min(1, raw / CONFIG.strikeThreshold);
$("banMultiplier").textContent = `×${mult.toFixed(2)}`;
$("banVerdict").textContent = banVerdict(mult, dist, omens.length);
$("strikeFill").style.width = `${dist * 100}%`;
// volatility = stddev of menace, normalized to 0..1 over [0,2]
const lv = omens.map((o) => o.menace);
const mean = lv.reduce((a, b) => a + b, 0) / (lv.length || 1);
const sd = Math.sqrt(lv.reduce((a, b) => a + (b - mean) ** 2, 0) / (lv.length || 1));
const vol = Math.min(1, sd / 2);
const vi = Math.min(VOL_LABELS.length - 1, Math.floor(vol * VOL_LABELS.length));
$("volLabel").textContent = omens.length ? `${VOL_LABELS[vi]} (${sd.toFixed(2)})` : "—";
$("volFill").style.width = `${(omens.length ? vol : 0) * 100}%`;
$("volNote").textContent = omens.length
? `${omens.length} omen${omens.length === 1 ? "" : "s"} in ${CONFIG.banWindowHours}h, avg menace ${mean.toFixed(1)}/5`
: "no data → volatility unknown, which is itself volatile";
$("omenList").innerHTML = omens.length
? omens.slice(0, 8).map((o) => `<li>
<span class="who">${esc(o.mod)}</span>
<span class="menace">[${o.menace}/5]</span>
${esc(o.text).slice(0, 70)}
<span class="when">${fmtTZ(o.at)}</span>
</li>`).join("")
: `<li class="empty">No omens reported. Mia has not joked about “Updates” in 48h. Suspicious.</li>`;
}
/* ---------- lore marquee ---------- */
const LORE = [
"🧾 GRILLIKUITTI: 1× UPDATE — €0.00 — SIS. ALV 14%",
"🔧 K-RAUTA REMINDER: 'update' ei löydy hyllystä, kysy henkilökunnalta",
"🌭 makkara paistuu, Wolfy päivittää",
"📦 SKU 404-UPDATE: varastossa 0 kpl, tilattavissa",
"🐺 tally so far is audited by three wolves and a receipt printer",
"⚠️ Ban Risk Multiplier™ is hypothetical — your actual mileage may be banned",
"🛠️ K-Rauta auki 7–21, Wolfy auki aina",
"🧾 palautusoikeus 14 päivää, päivityksiin ei palautusoikeutta",
];
$("loreMarquee").textContent = " · " + LORE.join(" · ") + " · " + LORE.join(" · ");
/* ---------- confetti ---------- */
function confetti() {
const c = $("confetti");
const ctx = c.getContext("2d");
c.width = innerWidth; c.height = innerHeight;
const parts = Array.from({ length: 140 }, () => ({
x: Math.random() * c.width, y: -20 - Math.random() * c.height * .3,
vy: 2 + Math.random() * 4, vx: -1.5 + Math.random() * 3,
s: 4 + Math.random() * 6, r: Math.random() * Math.PI,
vr: -0.1 + Math.random() * 0.2,
col: ["#ffb347", "#ff8c1a", "#ff5d5d", "#7dd87d", "#f5e6c8"][Math.floor(Math.random() * 5)],
}));
let frames = 0;
(function anim() {
ctx.clearRect(0, 0, c.width, c.height);
for (const p of parts) {
p.x += p.vx; p.y += p.vy; p.r += p.vr;
ctx.save(); ctx.translate(p.x, p.y); ctx.rotate(p.r);
ctx.fillStyle = p.col; ctx.fillRect(-p.s / 2, -p.s / 2, p.s, p.s * .6);
ctx.restore();
}
if (++frames < 220) requestAnimationFrame(anim);
else ctx.clearRect(0, 0, c.width, c.height);
})();
}
/* ---------- boot ---------- */
loadKeywords().then(loadSightings);
setInterval(loadSightings, CONFIG.pollMs);
loadOdds(); setInterval(loadOdds, CONFIG.oddsPollMs);
loadBanRisk(); setInterval(loadBanRisk, CONFIG.pollMs);