From e8a2b086b00cef936c1f8a589e20f92cfec62e15 Mon Sep 17 00:00:00 2001 From: lakca <912910011@qq.com> Date: Thu, 1 Jun 2023 18:02:48 +0800 Subject: [PATCH] fix download judgement. 1. support download attribute of anchor. 2. click link with meta key pressed to download any link, instead of judging the suffix which may block the normal page likes xxx.html, could be also not able to download files implied by the response headers. --- src-tauri/src/inject/event.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.js index c9bd3ee..3ef7317 100644 --- a/src-tauri/src/inject/event.js +++ b/src-tauri/src/inject/event.js @@ -127,16 +127,16 @@ document.addEventListener('DOMContentLoaded', () => { return; } + let filename = anchorElement.download ? anchorElement.download : getFilenameFromUrl(absoluteUrl) // Process download links for Rust to handle. - if ( - /\.[a-zA-Z0-9]+$/i.test(removeUrlParameters(absoluteUrl)) && - !externalDownLoadLink() + if ((anchorElement.download /* download attribute */ || e.metaKey /* Click anchor with meta key pressed could download any kind of resource. */) + && !externalDownLoadLink() ) { e.preventDefault(); invoke('download_file', { params: { url: absoluteUrl, - filename: getFilenameFromUrl(absoluteUrl), + filename, }, }); }