console.log("[KILLFEED] killfeed.js loaded"); const kfWrap = document.getElementById("killfeed"); function safeText(s) { return String(s ?? "").replace(/[&<>"']/g, (c) => ({ "&":"&", "<":"<", ">":">", '"':""", "'":"'" }[c])); } function rgbCss(rgb) { const a = Array.isArray(rgb) ? rgb : [255,255,255]; let r = Number(a[0]), g = Number(a[1]), b = Number(a[2]); if (!Number.isFinite(r)) r = 255; if (!Number.isFinite(g)) g = 255; if (!Number.isFinite(b)) b = 255; // brighten very dark colors slightly if (r < 70 && g < 70 && b < 70) { r = Math.min(255, r + 80); g = Math.min(255, g + 80); b = Math.min(255, b + 80); } return `rgb(${r},${g},${b})`; } function addKillfeedLine(payload) { if (!kfWrap) return; payload = payload || {}; // ✅ Death without a killer if (payload.isDeathOnly) { const victim = safeText(payload.victimName || "Unknown"); const vCss = rgbCss(payload.victimRgb); const line = document.createElement("div"); line.className = "kf-line"; line.innerHTML = ` ${victim} has died `; kfWrap.prepend(line); const maxLines = 6; while (kfWrap.children.length > maxLines) { kfWrap.lastElementChild?.remove(); } setTimeout(() => { line.classList.add("kf-out"); setTimeout(() => line.remove(), 300); }, 6000); return; } // ✅ Normal PvP line const killer = safeText(payload.killerName || "Unknown"); const victim = safeText(payload.victimName || "Unknown"); const weapon = safeText(payload.weapon || "Unknown"); const extras = []; if (payload.headshot) extras.push("HS"); const dist = Number(payload.distance || 0); if (Number.isFinite(dist) && dist > 0.1) extras.push(`${Math.round(dist)}m`); const extraText = extras.length ? `(${extras.join(" · ")})` : ""; const line = document.createElement("div"); line.className = "kf-line"; const kCss = rgbCss(payload.killerRgb); const vCss = rgbCss(payload.victimRgb); line.innerHTML = ` ${killer} [${weapon}] ${victim} ${extraText ? `${safeText(extraText)}` : ""} `; kfWrap.prepend(line); const maxLines = 6; while (kfWrap.children.length > maxLines) { kfWrap.lastElementChild?.remove(); } setTimeout(() => { line.classList.add("kf-out"); setTimeout(() => line.remove(), 300); }, 7000); } window.addEventListener("message", (event) => { const data = event.data || {}; if (data.type === "killfeed:add") { addKillfeedLine(data); } else if (data.type === "killfeed:clear") { if (kfWrap) kfWrap.innerHTML = ""; } });