feat: improve Firefox torrent extension link capture and peer status
- 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:
1 parent
7a1b4325f9
commit
82aaa9f11e
5 files changed
+38
-10
No files matched your search
Binary file not shown.
@@ -36,25 +36,37 @@
|
|||||||
if (ev.button !== 0 || ev.altKey || ev.ctrlKey || ev.metaKey || ev.shiftKey) {
|
if (ev.button !== 0 || ev.altKey || ev.ctrlKey || ev.metaKey || ev.shiftKey) {
|
||||||
return;
|
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;
|
if (!anchor) return;
|
||||||
|
const dataMagnet = anchor.getAttribute("data-magnet") || "";
|
||||||
const href = anchor.getAttribute("href") || "";
|
const href = anchor.getAttribute("href") || "";
|
||||||
let absUrl = "";
|
let absUrl = "";
|
||||||
try {
|
if (href) {
|
||||||
absUrl = new URL(href, window.location.href).href;
|
try {
|
||||||
} catch (_e) {
|
absUrl = new URL(href, window.location.href).href;
|
||||||
return;
|
} catch (_e) {
|
||||||
|
absUrl = "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
const isMagnet = absUrl.toLowerCase().startsWith("magnet:");
|
const magnetUri = dataMagnet.toLowerCase().startsWith("magnet:")
|
||||||
const isTorrent = /\.torrent(\?.*)?$/i.test(absUrl);
|
? dataMagnet
|
||||||
|
: absUrl.toLowerCase().startsWith("magnet:")
|
||||||
|
? absUrl
|
||||||
|
: "";
|
||||||
|
const isMagnet = Boolean(magnetUri);
|
||||||
|
const isTorrent = !isMagnet && /\.torrent([?#]|$)/i.test(absUrl);
|
||||||
if (!isMagnet && !isTorrent) return;
|
if (!isMagnet && !isTorrent) return;
|
||||||
|
|
||||||
ev.preventDefault();
|
ev.preventDefault();
|
||||||
ev.stopPropagation();
|
ev.stopPropagation();
|
||||||
|
ev.stopImmediatePropagation();
|
||||||
try {
|
try {
|
||||||
const res = await browser.runtime.sendMessage(
|
const res = await browser.runtime.sendMessage(
|
||||||
isMagnet
|
isMagnet
|
||||||
? { type: "addMagnet", uri: absUrl }
|
? { type: "addMagnet", uri: magnetUri }
|
||||||
: { type: "addTorrentUrl", url: absUrl }
|
: { type: "addTorrentUrl", url: absUrl }
|
||||||
);
|
);
|
||||||
if (res && res.ok) {
|
if (res && res.ok) {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"manifest_version": 2,
|
"manifest_version": 2,
|
||||||
"name": "Moon I2P Torrent & Proxy",
|
"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.",
|
"description": "Route .i2p browsing through moon-i2p and manage I2P BitTorrent + I2P DHT torrents from Firefox.",
|
||||||
"icons": {
|
"icons": {
|
||||||
"48": "icon.svg",
|
"48": "icon.svg",
|
||||||
|
|||||||
@@ -108,6 +108,19 @@ async function refresh() {
|
|||||||
const pct = Number(t.progress_pct || 0);
|
const pct = Number(t.progress_pct || 0);
|
||||||
const toggleLabel = t.paused ? "Resume" : "Pause";
|
const toggleLabel = t.paused ? "Resume" : "Pause";
|
||||||
const toggleType = t.paused ? "resumeTorrent" : "pauseTorrent";
|
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 `
|
return `
|
||||||
<div class="torrent-item" data-ih="${escapeHtml(t.info_hash)}">
|
<div class="torrent-item" data-ih="${escapeHtml(t.info_hash)}">
|
||||||
<div class="row" style="justify-content:space-between;">
|
<div class="row" style="justify-content:space-between;">
|
||||||
@@ -116,12 +129,14 @@ async function refresh() {
|
|||||||
</div>
|
</div>
|
||||||
<div class="progress-track"><div class="progress-fill" style="width:${pct}%"></div></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;">
|
<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">
|
<span class="row">
|
||||||
<button class="secondary act-btn" data-act="${toggleType}" data-ih="${escapeHtml(t.info_hash)}">${toggleLabel}</button>
|
<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>
|
<button class="danger act-btn" data-act="removeTorrent" data-ih="${escapeHtml(t.info_hash)}">Remove</button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
${trackerHtml}
|
||||||
|
${peersHtml}
|
||||||
${t.error ? `<div class="msg err">${escapeHtml(t.error)}</div>` : ""}
|
${t.error ? `<div class="msg err">${escapeHtml(t.error)}</div>` : ""}
|
||||||
</div>
|
</div>
|
||||||
`;
|
`;
|
||||||
|
|||||||
@@ -298,6 +298,7 @@ trap cleanup EXIT INT TERM
|
|||||||
|
|
||||||
"$ROUTER_BIN" \
|
"$ROUTER_BIN" \
|
||||||
--public \
|
--public \
|
||||||
|
--debug \
|
||||||
--sam "127.0.0.1:$SAM_PORT" \
|
--sam "127.0.0.1:$SAM_PORT" \
|
||||||
--http-proxy "127.0.0.1:$PROXY_PORT" \
|
--http-proxy "127.0.0.1:$PROXY_PORT" \
|
||||||
--torrent-api "127.0.0.1:$API_PORT" \
|
--torrent-api "127.0.0.1:$API_PORT" \
|
||||||
|
|||||||
Reference in new issue
Block a user