Initial commit: NZB → SABnzbd Chrome extensie
This commit is contained in:
commit
0034676f52
11 changed files with 535 additions and 0 deletions
76
content.js
Normal file
76
content.js
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
// 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 <a>-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
|
||||
Loading…
Reference in a new issue