Files
magnf-ext-poc/popup.js
T
kiskaadee 6bb6b3a1ea feat(popup): add toolbar action popup for link inspection and manual input
- Detect stored captured magnet link and show status indicator
- Provide Continue button to launch pairing page with captured link
- Add manual entry field and demo link filler for quick testing
2026-09-25 16:45:28 -05:00

57 lines
1.7 KiB
JavaScript

// popup.js for Magnetflix toolbar popup
const browserAPI = window.browser || window.chrome;
const SAMPLE_MAGNET = "magnet:?xt=urn:btih:1234567890abcdef1234567890abcdef12345678&dn=Perfect.Blue.1997.1080p.BluRay.x264";
document.addEventListener("DOMContentLoaded", () => {
const capturedPanel = document.getElementById("captured-state");
const manualPanel = document.getElementById("manual-state");
const magnetDisplay = document.getElementById("magnet-display");
const manualInput = document.getElementById("manual-magnet-input");
const btnContinueCaptured = document.getElementById("btn-continue-captured");
const btnContinueManual = document.getElementById("btn-continue-manual");
const btnLoadDemo = document.getElementById("btn-load-demo");
let currentCapturedMagnet = "";
// Check if a magnet was captured recently (within last 24h)
browserAPI.storage.local.get(["lastMagnet", "lastCapturedAt"], (result) => {
if (result && result.lastMagnet) {
currentCapturedMagnet = result.lastMagnet;
magnetDisplay.textContent = currentCapturedMagnet;
capturedPanel.classList.remove("hidden");
}
});
function openApp(magnetUrl) {
browserAPI.runtime.sendMessage(
{
action: "open_app",
magnet: magnetUrl
},
() => {
window.close();
}
);
}
btnContinueCaptured.addEventListener("click", () => {
if (currentCapturedMagnet) {
openApp(currentCapturedMagnet);
}
});
btnContinueManual.addEventListener("click", () => {
const val = manualInput.value.trim();
if (val) {
openApp(val);
} else {
manualInput.focus();
}
});
btnLoadDemo.addEventListener("click", () => {
manualInput.value = SAMPLE_MAGNET;
});
});