98 lines
3.7 KiB
JavaScript
98 lines
3.7 KiB
JavaScript
document.addEventListener("DOMContentLoaded", () => {
|
|
const win = document.getElementById("browser-window");
|
|
const closeBtn = document.getElementById("close-btn");
|
|
|
|
// Lane status (Lane B Removed)
|
|
const statusLaneA = document.getElementById("status-laneA");
|
|
|
|
// Recent vehicles log
|
|
const recentVehicles = document.getElementById("recent-vehicles");
|
|
|
|
// Totals / Summary
|
|
const totalTrucksEl = document.getElementById("total-trucks");
|
|
const avgWeightEl = document.getElementById("avg-weight");
|
|
const overweightCountEl = document.getElementById("overweight-count");
|
|
|
|
// Popup Logic (Keep existing)
|
|
const popup = document.createElement("div");
|
|
popup.id = "popup";
|
|
popup.style.position = "fixed";
|
|
popup.style.top = "20px";
|
|
popup.style.left = "20px";
|
|
popup.style.padding = "10px 20px";
|
|
popup.style.backgroundColor = "#000080";
|
|
popup.style.color = "#fff";
|
|
popup.style.fontFamily = "MS Sans Serif, Arial, sans-serif";
|
|
popup.style.fontSize = "14px";
|
|
popup.style.fontWeight = "bold";
|
|
popup.style.border = "2px solid #000";
|
|
popup.style.display = "none";
|
|
popup.style.zIndex = "9999";
|
|
popup.style.borderRadius = "4px";
|
|
document.body.appendChild(popup);
|
|
|
|
let recentVehiclesData = [];
|
|
let totalTrucks = 0;
|
|
let totalWeight = 0;
|
|
let overweightCount = 0;
|
|
let loggedVehicles = {};
|
|
|
|
window.addEventListener("message", (event) => {
|
|
const data = event.data;
|
|
|
|
if (data.action === "showUI") {
|
|
win.style.display = "block";
|
|
document.body.style.cursor = "default";
|
|
} else if (data.action === "hideUI") {
|
|
win.style.display = "none";
|
|
document.body.style.cursor = "none";
|
|
} else if (data.action === "showPopup") {
|
|
popup.innerText = data.text;
|
|
popup.style.display = "block";
|
|
} else if (data.action === "hidePopup") {
|
|
popup.style.display = "none";
|
|
} else if (data.action === "updateWeight") {
|
|
// Filter: Only update if the data is for LaneA
|
|
if (data.lane !== "LaneA") return;
|
|
|
|
const laneWeightEl = document.getElementById("laneA-weight");
|
|
laneWeightEl.innerText = data.weight ? data.weight + " LBS" : "-- LBS";
|
|
|
|
if (data.weight) {
|
|
statusLaneA.innerText = data.weight > 80000 ? `Lane A: ⚠️ Overweight` : `Lane A: Occupied`;
|
|
} else {
|
|
statusLaneA.innerText = `Lane A: Open`;
|
|
}
|
|
|
|
if (data.vehicle && data.weight && !loggedVehicles[data.vehicle]) {
|
|
loggedVehicles[data.vehicle] = true;
|
|
totalTrucks++;
|
|
totalWeight += data.weight;
|
|
if (data.weight > 80000) overweightCount++;
|
|
|
|
totalTrucksEl.innerText = totalTrucks;
|
|
avgWeightEl.innerText = Math.floor(totalWeight / totalTrucks);
|
|
overweightCountEl.innerText = overweightCount;
|
|
|
|
const entry = `${new Date().toLocaleTimeString()} - Lane A - ${data.weight} LBS`;
|
|
recentVehiclesData.unshift(entry);
|
|
if (recentVehiclesData.length > 10) recentVehiclesData.pop();
|
|
recentVehicles.innerHTML = recentVehiclesData.map(e => `<li>${e}</li>`).join("");
|
|
}
|
|
|
|
if (!data.weight && data.vehicle) {
|
|
loggedVehicles[data.vehicle] = false;
|
|
}
|
|
}
|
|
});
|
|
|
|
closeBtn.addEventListener("click", () => {
|
|
fetch(`https://${GetParentResourceName()}/closeUI`, {
|
|
method: 'POST',
|
|
body: JSON.stringify({})
|
|
}).finally(() => {
|
|
win.style.display = "none";
|
|
document.body.style.cursor = "none";
|
|
});
|
|
});
|
|
}); |