feat: improve Firefox torrent extension link capture and peer status
check / check (macos-latest) (push) Failing after 27s
check / check (ubuntu-latest) (push) Failing after 27s
check / check (windows-latest) (push) Failing after 27s

- Capture magnet links from data-magnet attributes and stop the page's own handlers from also firing on torrent and magnet links
- Treat .torrent URLs with fragments as torrent links
- Show tracker status, in-flight block counts, unchoked peer counts, and per-peer state in the torrent list
- Bump the extension to 0.1.2 and rebuild the .xpi
- Run the AppImage router with --debug
This commit is contained in:
nandi committed 2026-11-28 18:04:28 -08:00
1 parent 7a1b4325f9
commit 82aaa9f11e
5 files changed
+38 -10

No files matched your search

Binary file not shown.
+20 -8
View File
@@ -36,25 +36,37 @@
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;
const anchor =
ev.target && ev.target.closest
? ev.target.closest("a[href], a[data-magnet]")
: null;
if (!anchor) return;
const dataMagnet = anchor.getAttribute("data-magnet") || "";
const href = anchor.getAttribute("href") || "";
let absUrl = "";
try {
absUrl = new URL(href, window.location.href).href;
} catch (_e) {
return;
if (href) {
try {
absUrl = new URL(href, window.location.href).href;
} catch (_e) {
absUrl = "";
}
}
const isMagnet = absUrl.toLowerCase().startsWith("magnet:");
const isTorrent = /\.torrent(\?.*)?$/i.test(absUrl);
const magnetUri = dataMagnet.toLowerCase().startsWith("magnet:")
? dataMagnet
: absUrl.toLowerCase().startsWith("magnet:")
? absUrl
: "";
const isMagnet = Boolean(magnetUri);
const isTorrent = !isMagnet && /\.torrent([?#]|$)/i.test(absUrl);
if (!isMagnet && !isTorrent) return;
ev.preventDefault();
ev.stopPropagation();
ev.stopImmediatePropagation();
try {
const res = await browser.runtime.sendMessage(
isMagnet
? { type: "addMagnet", uri: absUrl }
? { type: "addMagnet", uri: magnetUri }
: { type: "addTorrentUrl", url: absUrl }
);
if (res && res.ok) {
+1 -1
View File
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Moon I2P Torrent & Proxy",
"version": "0.1.0",
"version": "0.1.2",
"description": "Route .i2p browsing through moon-i2p and manage I2P BitTorrent + I2P DHT torrents from Firefox.",
"icons": {
"48": "icon.svg",
+16 -1
View File
@@ -108,6 +108,19 @@ async function refresh() {
const pct = Number(t.progress_pct || 0);
const toggleLabel = t.paused ? "Resume" : "Pause";
const toggleType = t.paused ? "resumeTorrent" : "pauseTorrent";
const infTxt = t.inflight_blocks > 0 ? ` (+${t.inflight_blocks} blks)` : "";
const trackerHtml = t.last_tracker_status
? `<div style="color:var(--muted);font-size:11px;">Tracker: ${escapeHtml(t.last_tracker_status)}</div>`
: "";
const peers = Array.isArray(t.peers) ? t.peers : [];
const peersHtml = peers.length
? `<div style="color:var(--muted);font-size:11px;font-family:monospace;line-height:1.4;">${peers
.map(
(p) =>
`<div>peer ${escapeHtml(p.b32)}${p.client ? ` [${escapeHtml(p.client)}]` : ""} · st=${escapeHtml(String(p.state ?? ""))} ${p.choking ? "choked" : "unchoked"} · ${p.pieces || 0} pcs · inf=${p.in_flight || 0} · blks=${p.blocks_recv || 0}</div>`
)
.join("")}</div>`
: "";
return `
<div class="torrent-item" data-ih="${escapeHtml(t.info_hash)}">
<div class="row" style="justify-content:space-between;">
@@ -116,12 +129,14 @@ async function refresh() {
</div>
<div class="progress-track"><div class="progress-fill" style="width:${pct}%"></div></div>
<div class="row" style="justify-content:space-between;color:var(--muted);font-size:11px;">
<span>${fmtBytes(t.downloaded_bytes)} / ${fmtBytes(t.total_length)} · ${t.have_pieces}/${t.num_pieces} pcs · ${t.connected_peers}/${t.known_peers} peers</span>
<span>${fmtBytes(t.downloaded_bytes)} / ${fmtBytes(t.total_length)} · ${t.have_pieces}/${t.num_pieces} pcs${infTxt} · ${t.connected_peers}/${t.known_peers} peers (${t.unchoked_peers || 0} unchoked)</span>
<span class="row">
<button class="secondary act-btn" data-act="${toggleType}" data-ih="${escapeHtml(t.info_hash)}">${toggleLabel}</button>
<button class="danger act-btn" data-act="removeTorrent" data-ih="${escapeHtml(t.info_hash)}">Remove</button>
</span>
</div>
${trackerHtml}
${peersHtml}
${t.error ? `<div class="msg err">${escapeHtml(t.error)}</div>` : ""}
</div>
`;