forked from Phuongaz/AnyDecrypt
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
46 lines (37 loc) · 1.5 KB
/
script.js
File metadata and controls
46 lines (37 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function submitForm(event) {
event.preventDefault();
document.getElementById("loading").style.display = "block";
const ip = document.getElementById("ip").value;
const port = document.getElementById("port").value;
fetch(`/decrypt?ip=${ip}&port=${port}`)
.then(response => {
if (response.ok) {
return response.blob();
} else {
throw new Error('Decryption failed');
}
})
.then(blob => {
document.getElementById("loading").style.display = "none";
const url = window.URL.createObjectURL(blob);
const a = document.createElement("a");
a.href = url;
a.download = `${ip}.zip`;
const fileSize = (blob.size / (1024 * 1024)).toFixed(2);
const fileSizeText = `${fileSize} MB`;
const sizeInfo = document.createElement("p");
sizeInfo.innerText = `File size: ${fileSizeText}`;
document.getElementById("btn-decrypt").style.display = "none";
const downloadButton = document.getElementById("btn-download");
downloadButton.style.display = "block";
downloadButton.href = url;
downloadButton.addEventListener("click", () => {
a.click();
});
const container = document.getElementById("btn-download");
container.appendChild(sizeInfo);
})
.catch(error => {
console.error(error);
});
}