mirror of
https://github.com/nimbold/Firelink.git
synced 2026-07-26 12:08:27 +00:00
0ddea52db8
- Implement Firefox extension to intercept downloads and scrape selected links via context menus - Create LocalExtensionServer over TCP (localhost:6412) to receive links from the extension - Automatically package extension to firelink.xpi in create_app_bundle.sh - Add Integrations tab in SettingsView with one-click installer for Firefox variants - Modify ContentView and TrayMenuView to automatically open the Add Downloads window on extension trigger
38 lines
1.2 KiB
JavaScript
38 lines
1.2 KiB
JavaScript
// content.js
|
|
chrome.runtime.onMessage.addListener((request, sender, sendResponse) => {
|
|
if (request.action === "extractSelectionLinks") {
|
|
const selection = window.getSelection();
|
|
if (!selection || selection.rangeCount === 0) {
|
|
sendResponse({ links: [] });
|
|
return;
|
|
}
|
|
|
|
const links = new Set();
|
|
|
|
// Extract a tags from the selected range
|
|
for (let i = 0; i < selection.rangeCount; i++) {
|
|
const range = selection.getRangeAt(i);
|
|
const container = document.createElement("div");
|
|
container.appendChild(range.cloneContents());
|
|
|
|
const anchors = container.querySelectorAll("a");
|
|
anchors.forEach(a => {
|
|
if (a.href) {
|
|
// ensure the link is a full URL by using the current document's base URI if it's relative
|
|
try {
|
|
const url = new URL(a.getAttribute('href'), document.baseURI).href;
|
|
links.add(url);
|
|
} catch (e) {
|
|
// Invalid URL, fallback to just checking if it looks like a valid protocol
|
|
if (a.href.startsWith("http")) {
|
|
links.add(a.href);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
}
|
|
|
|
sendResponse({ links: Array.from(links) });
|
|
}
|
|
});
|