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
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user