Add shimmer
This commit is contained in:
@@ -143,11 +143,33 @@
|
||||
const logList = document.getElementById("logList");
|
||||
logList.innerHTML = "";
|
||||
if (tankData.logs) {
|
||||
const now = Date.now() / 1000;
|
||||
tankData.logs.forEach(log => {
|
||||
const li = document.createElement("li");
|
||||
// If log.date is a string, try to parse as epoch seconds
|
||||
let epoch = typeof log.date === 'number' ? log.date : Date.parse(log.date) / 1000;
|
||||
// timesago expects ms
|
||||
const ageHours = (now - epoch) / 3600;
|
||||
|
||||
// Color interpolation: 0h = #fff, 8h = #888
|
||||
let color;
|
||||
if (ageHours <= 0) {
|
||||
color = "#fff";
|
||||
} else if (ageHours >= 8) {
|
||||
color = "#888";
|
||||
} else {
|
||||
// Linear interpolation between #fff and #888
|
||||
const t = ageHours / 8;
|
||||
const r = Math.round(255 + (136 - 255) * t);
|
||||
const g = Math.round(255 + (136 - 255) * t);
|
||||
const b = Math.round(255 + (136 - 255) * t);
|
||||
color = `rgb(${r},${g},${b})`;
|
||||
}
|
||||
li.style.color = color;
|
||||
|
||||
// Add shimmer class if less than 8 hours old
|
||||
if (ageHours < 8) {
|
||||
li.classList.add("log-shimmer");
|
||||
}
|
||||
|
||||
li.textContent = `${window.timesago ? timesago(epoch * 1000) : log.date} — ${log.text}`;
|
||||
logList.appendChild(li);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user