"use strict"; (function () { function showToast(text, isError) { let el = document.getElementById("moon-i2p-torrent-toast"); if (!el) { el = document.createElement("div"); el.id = "moon-i2p-torrent-toast"; el.style.cssText = [ "position:fixed", "right:18px", "bottom:18px", "z-index:2147483647", "padding:10px 14px", "border-radius:10px", "font-family:system-ui,-apple-system,sans-serif", "font-size:13px", "color:#f8fafc", "box-shadow:0 8px 24px rgba(0,0,0,0.35)", "border:1px solid rgba(255,255,255,0.16)", "max-width:360px", ].join(";"); document.documentElement.appendChild(el); } el.style.background = isError ? "#991b1b" : "#0f172a"; el.textContent = text; clearTimeout(el._hideTimer); el._hideTimer = setTimeout(() => { if (el.parentNode) el.parentNode.removeChild(el); }, 4500); } document.addEventListener( "click", async (ev) => { if (ev.button !== 0 || ev.altKey || ev.ctrlKey || ev.metaKey || ev.shiftKey) { return; } const anchor = ev.target && ev.target.closest ? ev.target.closest("a[href]") : null; if (!anchor) return; const href = anchor.getAttribute("href") || ""; let absUrl = ""; try { absUrl = new URL(href, window.location.href).href; } catch (_e) { return; } const isMagnet = absUrl.toLowerCase().startsWith("magnet:"); const isTorrent = /\.torrent(\?.*)?$/i.test(absUrl); if (!isMagnet && !isTorrent) return; ev.preventDefault(); ev.stopPropagation(); try { const res = await browser.runtime.sendMessage( isMagnet ? { type: "addMagnet", uri: absUrl } : { type: "addTorrentUrl", url: absUrl } ); if (res && res.ok) { showToast(`Added to moon-i2p (${(res.info_hash || "").slice(0, 12)}...)`, false); } else { showToast(`moon-i2p error: ${(res && res.error) || "router offline?"}`, true); } } catch (err) { showToast(`moon-i2p error: ${err}`, true); } }, true ); })();