diff --git a/README.md b/README.md
index 00db4d4..2a88fc1 100644
--- a/README.md
+++ b/README.md
@@ -269,6 +269,13 @@ Pake's development can not be without these Hackers. They contributed a lot of c
Pake Actions
+
+
+
+
+ Santree
+
+ |
@@ -283,13 +290,6 @@ Pake's development can not be without these Hackers. They contributed a lot of c
孟世博
|
-
-
-
-
- Santree
-
- |
diff --git a/src-tauri/src/inject/event.js b/src-tauri/src/inject/event.js
index 388a96e..7a66cc7 100644
--- a/src-tauri/src/inject/event.js
+++ b/src-tauri/src/inject/event.js
@@ -156,6 +156,7 @@ document.addEventListener('DOMContentLoaded', () => {
}
let filename = anchorElement.download || getFilenameFromUrl(absoluteUrl);
+
// Process download links for Rust to handle.
// If the download attribute is set, the download attribute is used as the file name.
if (
@@ -261,29 +262,32 @@ function convertBlobUrlToBinary(blobUrl) {
});
}
+function downloadFromBlobUrl(blobUrl, filename) {
+ const tauri = window.__TAURI__;
+ convertBlobUrlToBinary(blobUrl).then((binary) => {
+ console.log('binary', binary);
+ tauri.fs.writeBinaryFile(filename, binary, {
+ dir: tauri.fs.BaseDirectory.Download,
+ }).then(() => {
+ window.pakeToast('Download successful, saved to download directory~');
+ });
+ });
+}
+
// detect blob download by createElement("a")
function detectDownloadByCreateAnchor() {
const createEle = document.createElement;
document.createElement = (el) => {
if (el !== "a") return createEle.call(document, el);
const anchorEle = createEle.call(document, el);
- const anchorClick = anchorEle.click;
- Object.defineProperties(anchorEle, {
- click: {
- get: () => {
- if (anchorEle.href && anchorEle.href.includes('blob:')) {
- const url = anchorEle.href;
- convertBlobUrlToBinary(url).then((binary) => {
- tauri.fs.writeBinaryFile(anchorEle.download || getFilenameFromUrl(url), binary, {
- dir: tauri.fs.BaseDirectory.Download,
- });
- });
- }
- return anchorClick.bind(anchorEle);
- }
+ // use addEventListener to avoid overriding the original click event.
+ anchorEle.addEventListener('click', () => {
+ const url = anchorEle.href;
+ if (window.blobToUrlCaches.has(url)) {
+ downloadFromBlobUrl(url, anchorEle.download || getFilenameFromUrl(url));
}
- })
+ });
return anchorEle;
}
|