// content.js — onderschept klikken op NZB-links // Patronen die duiden op een NZB-downloadlink const NZB_PATTERNS = [ /[?&]action=display/i, /[?&]page=getnzb/i, /\.nzb(\?|$)/i, /\/getnzb\//i, /\/download.*nzb/i, /nzb.*download/i ]; function isNzbLink(url) { return NZB_PATTERNS.some(pattern => pattern.test(url)); } function showToast(message, success = true) { const existing = document.getElementById("nzb-sabnzbd-toast"); if (existing) existing.remove(); const toast = document.createElement("div"); toast.id = "nzb-sabnzbd-toast"; toast.textContent = message; toast.style.cssText = ` position: fixed; bottom: 24px; right: 24px; z-index: 999999; background: ${success ? "#1a1a2e" : "#3d0000"}; color: ${success ? "#7ee8a2" : "#ff6b6b"}; border: 1px solid ${success ? "#7ee8a2" : "#ff6b6b"}; border-radius: 8px; padding: 12px 20px; font-family: system-ui, sans-serif; font-size: 14px; font-weight: 500; box-shadow: 0 4px 20px rgba(0,0,0,0.4); transition: opacity 0.3s ease; opacity: 1; max-width: 320px; `; document.body.appendChild(toast); setTimeout(() => { toast.style.opacity = "0"; setTimeout(() => toast.remove(), 300); }, 3500); } document.addEventListener("click", async (e) => { // Zoek het dichtstbijzijnde -element const anchor = e.target.closest("a"); if (!anchor) return; const href = anchor.href; if (!href) return; if (!isNzbLink(href)) return; // Onderschep de klik e.preventDefault(); e.stopPropagation(); showToast("⏳ NZB wordt verstuurd naar SABnzbd...", true); const response = await chrome.runtime.sendMessage({ type: "SEND_NZB", url: href }); if (response?.success) { showToast("✅ Toegevoegd aan SABnzbd!", true); } else { showToast(`❌ Mislukt: ${response?.error || "Onbekende fout"}`, false); } }, true); // useCapture = true zodat we vóór andere handlers zitten