refactor(code): Cleaned-up the code base

This commit is contained in:
2026-04-30 11:05:56 +03:00
parent a729b641b2
commit f0b723e35d
71 changed files with 6848 additions and 5394 deletions

View File

@@ -15,14 +15,7 @@ const zipOnly = boxPanel && boxPanel.dataset.zipOnly === "true";
let contextFile = null;
let lastStatusSignature = "";
function htmlEscape(value) {
return String(value || "")
.replaceAll("&", "&")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll('"', "&quot;")
.replaceAll("'", "&#39;");
}
const htmlEscape = window.WarpBoxUI.htmlEscape;
function showToast(message, type = "info") {
window.WarpBoxUI.toast(message, type, { target: toast });
@@ -302,23 +295,39 @@ function startStagedPolling(baseMS) {
window.setTimeout(tick, stages[0].interval);
}
function runBoxAction(action) {
const actions = {
"fake-close": () => showToast("Close clicked. The download window is emotionally attached.", "warning"),
minimize: () => showToast("Minimize clicked. WarpBox refuses to disappear quietly."),
"toggle-fit": () => {
document.body.classList.toggle("fit-window");
showToast("Maximize clicked. The window is doing its best.");
},
};
actions[action]?.();
}
function runContextAction(action, item) {
const actions = {
preview: () => previewFile(item),
download: () => downloadFile(item),
properties: () => showProperties(item),
};
actions[action]?.();
}
document.addEventListener("click", (event) => {
const action = event.target.closest("[data-action]")?.dataset.action;
if (action === "fake-close") showToast("Close clicked. The download window is emotionally attached.", "warning");
if (action === "minimize") showToast("Minimize clicked. WarpBox refuses to disappear quietly.");
if (action === "toggle-fit") {
document.body.classList.toggle("fit-window");
showToast("Maximize clicked. The window is doing its best.");
}
if (action) runBoxAction(action);
const contextAction = event.target.closest("[data-context-action]")?.dataset.contextAction;
if (contextAction && contextFile) {
event.preventDefault();
const item = contextFile;
closeContextMenu();
if (contextAction === "preview") previewFile(item);
if (contextAction === "download") downloadFile(item);
if (contextAction === "properties") showProperties(item);
runContextAction(contextAction, item);
return;
}