🎨 Optimize the code of version 1.3.

This commit is contained in:
Tw93
2023-06-07 13:16:25 +08:00
parent e9486e1b67
commit 9221bbce10
5 changed files with 184 additions and 182 deletions

View File

@@ -75,6 +75,12 @@ document.addEventListener('DOMContentLoaded', () => {
background: #fff;
color: #11182B;
}
#pakeUrlInput {
min-width: 320px;
text-align: left;
min-height: 30px;
}
`;
const modalDiv = document.createElement('div');

View File

@@ -130,20 +130,19 @@ document.addEventListener('DOMContentLoaded', () => {
const detectAnchorElementClick = (e) => {
const anchorElement = e.target.closest('a');
if (anchorElement && anchorElement.href) {
const target = anchorElement.target;
anchorElement.target = '_self';
const hrefUrl = new URL(anchorElement.href);
const absoluteUrl = hrefUrl.href;
// Convert blob url to binary file
if (absoluteUrl.includes('blob:')) {
// convert blob url to binary file
converBlobUrlToBinary(absoluteUrl).then(binary => {
const tarui = window.__TAURI__;
tarui.fs.writeBinaryFile(anchorElement.download, binary, {
dir: tarui.fs.BaseDirectory.Download,
convertBlobUrlToBinary(absoluteUrl).then(binary => {
const tauri = window.__TAURI__;
tauri.fs.writeBinaryFile(anchorElement.download, binary, {
dir: tauri.fs.BaseDirectory.Download,
});
})
return;
}
@@ -177,7 +176,6 @@ document.addEventListener('DOMContentLoaded', () => {
// Prevent some special websites from executing in advance, before the click event is triggered.
document.addEventListener('mousedown', detectAnchorElementClick);
document.addEventListener('click', detectAnchorElementClick);
collectUrlToBlobs();
@@ -246,19 +244,19 @@ function collectUrlToBlobs() {
const url = backupCreateObjectURL.call(window.URL, blob);
window.blobToUrlCaches.set(url, blob);
return url;
}
}
}
function converBlobUrlToBinary(blobUrl) {
function convertBlobUrlToBinary(blobUrl) {
return new Promise((resolve) => {
const blob = window.blobToUrlCaches.get(blobUrl);
const reader = new FileReader();
reader.readAsArrayBuffer(blob);
reader.onload = () => {
resolve(reader.result);
};
})
}
}