Skip to content

Commit

Permalink
chore: Refine the exportAllLinks function
Browse files Browse the repository at this point in the history
  • Loading branch information
alexhua committed May 24, 2024
1 parent 964963d commit fd1c778
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 7 deletions.
13 changes: 7 additions & 6 deletions background.js
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ function onMenuClick(info, tab) {
}
} else if (info.menuItemId == "MENU_EXPORT_ALL" && !tab.url.startsWith("chrome")) {
chrome.scripting.executeScript({
target: { tabId: tab.id, allFrames: false, frameIds: [info.frameId] },
target: { tabId: tab.id, allFrames: !info.frameId, frameIds: info.frameId ? [info.frameId] : undefined },
func: exportAllLinks,
args: [Configs.allowedExts, Configs.blockedExts]
});
Expand Down Expand Up @@ -997,8 +997,7 @@ function exportAllLinks(allowedExts, blockedExts) {
let filename = url.pathname.split('/').pop();
let ext = filename.includes('.') ? filename.split('.').pop() : '';
let valid = false;

if (url.protocol == "magnet:") {
if (url.protocol == "magnet:" || (tagName == "VIDEO" || tagName == "AUDIO") && url.protocol.startsWith("http")) {
valid = true;
} else if (/^http|ftp|sftp/.test(url.protocol)) {
if (allowedExts.includes(ext) || allowedExts.includes('*')) {
Expand All @@ -1024,12 +1023,14 @@ function exportAllLinks(allowedExts, blockedExts) {
console.warn("DownloadAllLinks: Invalid URL found, URL=", link);
}
}

if (links.length > 0) {
let downloadItem = { filename: '', url: links.join('\n'), referrer: window.location.href, multiTask: true };
chrome.runtime.sendMessage({ type: "EXPORT_ALL", data: downloadItem });
} else {
let des = chrome.i18n.getMessage("exportAllFailedDes");
alert("\nAria2-Explorer: " + des);
setTimeout(() => {
if (document.hasFocus()) {
alert("\nAria2-Explorer: " + chrome.i18n.getMessage("exportAllFailedDes"));
}
}, 300);
}
}
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "__MSG_appName__",
"short_name": "A2E",
"version": "2.4.3",
"version": "2.5.0",
"manifest_version": 3,
"minimum_chrome_version": "100.0.0",
"default_locale": "en",
Expand Down

0 comments on commit fd1c778

Please sign in to comment.