const authBadge = document.getElementById("authBadge")!; const detectionsEl = document.getElementById("detections")!; const checkNumberBtn = document.getElementById("checkNumberBtn")!; const reportSpamBtn = document.getElementById("reportSpamBtn")!; const openOptionsLink = document.getElementById("openOptions")!; function showDetection(detection: { type: string; value: string; timestamp: number; }) { const date = new Date(detection.timestamp).toLocaleTimeString(); const typeClass = detection.type === "phishing" ? "phishing" : "spam"; return `
${detection.type.replace("_", " ")} · ${date}
${detection.value}
`; } async function updateAuthStatus() { try { const status = await chrome.runtime.sendMessage({ type: "GET_AUTH_STATUS" }); if (status?.linked) { authBadge.textContent = "Linked"; authBadge.className = "status-badge linked"; } else { authBadge.textContent = "Unlinked"; authBadge.className = "status-badge unlinked"; } } catch { authBadge.textContent = "Unlinked"; authBadge.className = "status-badge unlinked"; } } async function updateDetections() { try { const detections = await chrome.runtime.sendMessage({ type: "GET_DETECTIONS" }); if (detections && detections.length > 0) { detectionsEl.innerHTML = detections.map(showDetection).join(""); } } catch { // Background may not be ready } } checkNumberBtn.addEventListener("click", () => { const phoneNumber = prompt("Enter phone number to check (e.g. +1234567890):"); if (phoneNumber) { chrome.runtime.sendMessage( { type: "CHECK_NUMBER", phoneNumber }, (result) => { if (result) { alert( result.isSpam ? `⚠️ Spam detected (score: ${result.score})` : "✅ No spam detected", ); updateDetections(); } }, ); } }); reportSpamBtn.addEventListener("click", () => { const phoneNumber = prompt("Enter phone number to report as spam:"); if (phoneNumber) { chrome.runtime.sendMessage( { type: "CHECK_NUMBER", phoneNumber }, () => updateDetections(), ); } }); openOptionsLink.addEventListener("click", (e) => { e.preventDefault(); chrome.runtime.openOptionsPage(); }); updateAuthStatus(); updateDetections();