diff --git a/views/index.ejs b/views/index.ejs index b52c7f8..29879ec 100644 --- a/views/index.ejs +++ b/views/index.ejs @@ -611,6 +611,19 @@ .then(data => { if (data) { car1 = data.data; + var timestamp = new Date(car1.timestamp); + timestamp.setHours(timestamp.getHours() + 1); + var currentTimestamp = new Date(); + var timeDifferenceInSeconds = (currentTimestamp - timestamp) / 1000; + if (timeDifferenceInSeconds < 60) { + timestampBackgroundColor = 'rgba(0, 128, 0, 0.7)'; + } else if (timeDifferenceInSeconds >= 60 && timeDifferenceInSeconds <= 300) { + timestampBackgroundColor = 'rgba(255, 165, 0, 0.7)'; + } else { + timestampBackgroundColor = 'rgba(255, 0, 0, 0.7)'; + } + document.getElementById('car1Panel').textContent = timestamp.toLocaleString('en-US', { hour12: false }) + ", (-" + timeDifferenceInSeconds + "s)"; + document.getElementById('car1Panel').style.backgroundColor = timestampBackgroundColor; } else { console.log('Received undefined data from the server'); } @@ -629,6 +642,19 @@ .then(data => { if (data) { car2 = data.data; + var timestamp = new Date(car2.timestamp); + timestamp.setHours(timestamp.getHours() + 1); + var currentTimestamp = new Date(); + var timeDifferenceInSeconds = (currentTimestamp - timestamp) / 1000; + if (timeDifferenceInSeconds < 60) { + timestampBackgroundColor = 'rgba(0, 128, 0, 0.7)'; + } else if (timeDifferenceInSeconds >= 60 && timeDifferenceInSeconds <= 300) { + timestampBackgroundColor = 'rgba(255, 165, 0, 0.7)'; + } else { + timestampBackgroundColor = 'rgba(255, 0, 0, 0.7)'; + } + document.getElementById('car2Panel').textContent = timestamp.toLocaleString('en-US', { hour12: false }) + ", (-" + timeDifferenceInSeconds + "s)"; + document.getElementById('car2Panel').style.backgroundColor = timestampBackgroundColor; } else { console.log('Received undefined data from the server'); } @@ -646,6 +672,19 @@ .then(data => { if (data) { car3 = data.data; + var timestamp = new Date(car3.timestamp); + timestamp.setHours(timestamp.getHours() + 1); + var currentTimestamp = new Date(); + var timeDifferenceInSeconds = (currentTimestamp - timestamp) / 1000; + if (timeDifferenceInSeconds < 60) { + timestampBackgroundColor = 'rgba(0, 128, 0, 0.7)'; + } else if (timeDifferenceInSeconds >= 60 && timeDifferenceInSeconds <= 300) { + timestampBackgroundColor = 'rgba(255, 165, 0, 0.7)'; + } else { + timestampBackgroundColor = 'rgba(255, 0, 0, 0.7)'; + } + document.getElementById('car3Panel').textContent = timestamp.toLocaleString('en-US', { hour12: false }) + ", (-" + timeDifferenceInSeconds + "s)"; + document.getElementById('car3Panel').style.backgroundColor = timestampBackgroundColor; } else { console.log('Received undefined data from the server'); }