From 5f789c54f9f1206d435cbfb33f32edd9185b1520 Mon Sep 17 00:00:00 2001 From: Kakarot <57848836+GhzGarage@users.noreply.github.com> Date: Sat, 10 Feb 2024 17:16:21 -0600 Subject: [PATCH] Updates/improvements --- html/js/app.js | 66 +++++++++++++++++++++++++++++--------------------- 1 file changed, 39 insertions(+), 27 deletions(-) diff --git a/html/js/app.js b/html/js/app.js index 27584a5..9ea0df3 100644 --- a/html/js/app.js +++ b/html/js/app.js @@ -6,86 +6,98 @@ document.addEventListener("DOMContentLoaded", function () { }; const targetEye = document.getElementById("target-eye"); - let targetLabel = document.getElementById("target-label"); - let TargetEyeStyleObject = targetEye.style; + const targetLabel = document.getElementById("target-label"); + const TargetEyeStyleObject = targetEye.style; function OpenTarget() { - targetLabel.innerHTML = ""; + targetLabel.textContent = ""; targetEye.style.display = "block"; targetEye.className = config.StandardEyeIcon; TargetEyeStyleObject.color = config.StandardColor; } function CloseTarget() { - targetLabel.innerHTML = ""; + targetLabel.textContent = ""; targetEye.style.display = "none"; } + function createTargetOption(index, itemData) { + if (itemData !== null) { + index = Number(index) + 1; + const targetOption = document.createElement("div"); + targetOption.id = `target-option-${index}`; + targetOption.style.marginBottom = "0.2vh"; + targetOption.style.borderRadius = "0.15rem"; + targetOption.style.padding = "0.45rem"; + targetOption.style.background = "rgba(23, 23, 23, 40%)"; + targetOption.style.color = config.StandardColor; + const targetIcon = document.createElement("span"); + targetIcon.id = `target-icon-${index}`; + const icon = document.createElement("i"); + icon.className = itemData.icon; + targetIcon.appendChild(icon); + targetIcon.appendChild(document.createTextNode(" ")); + targetOption.appendChild(targetIcon); + targetOption.appendChild(document.createTextNode(itemData.label)); + targetLabel.appendChild(targetOption); + } + } + function FoundTarget(item) { if (item.data) { targetEye.className = item.data; } TargetEyeStyleObject.color = config.SuccessColor; - targetLabel.innerHTML = ""; + targetLabel.textContent = ""; for (let [index, itemData] of Object.entries(item.options)) { - if (itemData !== null) { - index = Number(index) + 1; - targetLabel.innerHTML += `
${itemData.label}
`; - } + createTargetOption(index, itemData); } } function ValidTarget(item) { - targetLabel.innerHTML = ""; + targetLabel.textContent = ""; for (let [index, itemData] of Object.entries(item.data)) { - if (itemData !== null) { - index = Number(index) + 1; - targetLabel.innerHTML += `
${itemData.label}
`; - } + createTargetOption(index, itemData); } } function LeftTarget() { - targetLabel.innerHTML = ""; + targetLabel.textContent = ""; TargetEyeStyleObject.color = config.StandardColor; targetEye.className = config.StandardEyeIcon; } function handleMouseDown(event) { - let element = event.target; + const element = event.target; // use const instead of let if (element.id) { const split = element.id.split("-"); - if (split[0] === "target" && split[1] !== "eye" && event.button == 0) { + if (split[0] === "target" && split[1] !== "eye" && event.button === 0) { fetch(`https://${GetParentResourceName()}/selectTarget`, { method: "POST", headers: { "Content-Type": "application/json; charset=UTF-8" }, body: JSON.stringify(split[2]), - }); - targetLabel.innerHTML = ""; + }).catch((error) => console.error("Error:", error)); + targetLabel.textContent = ""; } } - if (event.button == 2) { + if (event.button === 2) { LeftTarget(); fetch(`https://${GetParentResourceName()}/leftTarget`, { method: "POST", headers: { "Content-Type": "application/json; charset=UTF-8" }, body: "", - }); + }).catch((error) => console.error("Error:", error)); } } function handleKeyDown(event) { - if (event.key == "Escape" || event.key == "Backspace") { + if (event.key === "Escape" || event.key === "Backspace") { CloseTarget(); fetch(`https://${GetParentResourceName()}/closeTarget`, { method: "POST", headers: { "Content-Type": "application/json; charset=UTF-8" }, body: "", - }); + }).catch((error) => console.error("Error:", error)); } }