This commit is contained in:
Booteille 2024-11-14 21:04:20 +01:00
parent 6462234788
commit 9cc02d3384
No known key found for this signature in database
GPG Key ID: 0AB6C6CA01272646
1 changed files with 12 additions and 17 deletions

View File

@ -18,10 +18,7 @@ document.addEventListener("DOMContentLoaded", () => {
let go = true; let go = true;
filesizeDOM.innerHTML = filesize( filesizeDOM.innerHTML = filesize(
filesizeDOM.attributes.getNamedItem("data-filesize").value, filesizeDOM.attributes.getNamedItem("data-filesize").value
{
base: 10,
}
); );
if (isPasswordNeeded()) { if (isPasswordNeeded()) {
@ -51,7 +48,7 @@ const startDownload = () => {
}); });
document.getElementById("abort").onclick = () => { document.getElementById("abort").onclick = () => {
remove(["please-wait", "pbd", "loading", "abort"]); removeElements(["please-wait", "pbd", "loading", "abort"]);
job.terminate(); job.terminate();
@ -69,11 +66,11 @@ const startDownload = () => {
.mapErr((error) => { .mapErr((error) => {
addAlert(error.message); addAlert(error.message);
warnOnReload(false); warnOnReload(false);
remove(["abort"]); removeElements(["abort"]);
}) })
.andThen((job) => { .andThen((job) => {
notify(i18n.fileDownloaded, job.lufiFile.name); notify(i18n.fileDownloaded, job.lufiFile.name);
remove(["please-wait", "loading"]); removeElements(["please-wait", "loading"]);
const pbd = document.getElementById("pbd"); const pbd = document.getElementById("pbd");
pbd.className = "center-align"; pbd.className = "center-align";
@ -112,7 +109,11 @@ const startDownload = () => {
}); });
}; };
const remove = (elements) => { /**
* Remove elements using their id
* @param elements
*/
const removeElements = (elements) => {
elements.forEach((id) => { elements.forEach((id) => {
if (document.getElementById(id)) { if (document.getElementById(id)) {
document.getElementById(id).remove(); document.getElementById(id).remove();
@ -147,7 +148,7 @@ const onPasswordEvents = () => {
// Something's wring // Something's wring
const addAlert = (msg) => { const addAlert = (msg) => {
// remove(["please-wait"]); removeElements(["please-wait"]);
let pbd = document.getElementsByClassName("file-progress")[0]; let pbd = document.getElementsByClassName("file-progress")[0];
@ -163,11 +164,7 @@ const addAlert = (msg) => {
}; };
const warnOnReload = (toWarn = true) => { const warnOnReload = (toWarn = true) => {
if (toWarn) { window.onbeforeunload = toWarn ? confirmExit : null;
window.onbeforeunload = confirmExit;
} else {
window.onbeforeunload = null;
}
}; };
const updateProgress = (lufiFile) => { const updateProgress = (lufiFile) => {
@ -201,9 +198,7 @@ const showZipContent = (zipFile) => {
files.forEach((file) => { files.forEach((file) => {
innerHTML += `<li> innerHTML += `<li>
${escapeHtml(file.name)} ${escapeHtml(file.name)}
(${filesize(file.size, { (${filesize(file.size)})
base: 10,
})})
<a href="#" <a href="#"
download="${escapeHtml(file.name)}" download="${escapeHtml(file.name)}"
class="download-zip-content" class="download-zip-content"