/** * PhishShield — content.js */ function extractGmail() { try { const subject = document.querySelector("h2.hP")?.innerText || document.title; const sender = document.querySelector(".gD")?.getAttribute("email") || ""; const body = document.querySelector(".a3s.aiL")?.innerText || document.querySelector(".ii.gt")?.innerText || document.body.innerText.slice(0, 4000); return { type: "email", subject, sender, body: body.slice(0, 4000) }; } catch (_) { return { type: "email", subject: document.title, sender: "", body: document.body.innerText.slice(0, 4000) }; } } function extractOutlook() { try { const subject = document.querySelector("[data-testid='subject']")?.innerText || document.querySelector(".allowTextSelection")?.innerText?.split("\n")[0] || document.title; const sender = document.querySelector(".ms-Persona-primaryText")?.innerText || ""; const body = document.querySelector("[data-testid='messageBody']")?.innerText || document.querySelector(".ReadingPaneContent")?.innerText || document.body.innerText.slice(0, 4000); return { type: "email", subject, sender, body: body.slice(0, 4000) }; } catch (_) { return { type: "email", subject: document.title, sender: "", body: document.body.innerText.slice(0, 4000) }; } } function extractPageData() { const host = window.location.hostname; if (host.includes("mail.google.com")) return extractGmail(); if (host.includes("outlook")) return extractOutlook(); // Normal Webpage return { type: "website", url: window.location.href, title: document.title, body: document.body.innerText.slice(0, 4000) }; } function injectWarningBanner(riskLevel, reason) { document.getElementById("ps-warning-banner")?.remove(); if (riskLevel === "Safe") return; const colors = { "High Risk": { bg: "rgba(248,81,73,0.15)", border: "#f85149", icon: "🚨" }, "Medium Risk": { bg: "rgba(210,153,34,0.15)", border: "#d29922", icon: "⚠️" }, "Low Risk": { bg: "rgba(232,81,10,0.12)", border: "#E8510A", icon: "⚡" }, }; const { bg, border, icon } = colors[riskLevel] || colors["Low Risk"]; const banner = document.createElement("div"); banner.id = "ps-warning-banner"; banner.style.cssText = ` position: fixed; top: 60px; right: 16px; z-index: 999999; background: ${bg}; border: 1px solid ${border}; border-radius: 8px; padding: 12px 16px; max-width: 320px; backdrop-filter: blur(8px); font-family: 'DM Sans', -apple-system, sans-serif; box-shadow: 0 4px 20px rgba(0,0,0,0.4); animation: ps-slide-in 0.3s ease; `; banner.innerHTML = `
${reason}
Powered by PhishShield AI
`; document.body.appendChild(banner); banner.querySelector("#ps-close-btn").addEventListener("click", () => banner.remove()); setTimeout(() => banner.remove(), 12000); } chrome.runtime.onMessage.addListener((msg, _sender, sendResponse) => { if (msg.action === "extractEmail" || msg.action === "extractPage") { sendResponse(extractPageData()); } if (msg.action === "showWarning") { injectWarningBanner(msg.riskLevel, msg.reason); } return true; });