You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
28 lines
1.3 KiB
JavaScript
28 lines
1.3 KiB
JavaScript
function updateOnlineDurations() {
|
|
document.querySelectorAll('.visitor').forEach(visitorDiv => {
|
|
if (visitorDiv.querySelector('.online')) {
|
|
const durationElem = visitorDiv.querySelector('.duration');
|
|
const currentText = durationElem.textContent;
|
|
const [hours, minutes, seconds] = currentText.split(':').map(Number);
|
|
const totalSeconds = hours * 3600 + minutes * 60 + seconds;
|
|
|
|
// Increment the duration by 1 second
|
|
const updatedTotalSeconds = totalSeconds + 1;
|
|
const updatedHours = Math.floor(updatedTotalSeconds / 3600);
|
|
const updatedMinutes = Math.floor((updatedTotalSeconds % 3600) / 60);
|
|
const updatedSeconds = updatedTotalSeconds % 60;
|
|
|
|
// Format the updated duration
|
|
const formattedDuration =
|
|
(updatedHours > 0 ? `${String(updatedHours).padStart(2, '0') + ':' : ''}` +
|
|
`${String(updatedMinutes).padStart(2, '0')}:${String(updatedSeconds).padStart(2, '0')}`);
|
|
|
|
// Update the duration element
|
|
durationElem.textContent = formattedDuration;
|
|
}
|
|
});
|
|
}
|
|
|
|
// Call this function at intervals to update durations
|
|
setInterval(updateOnlineDurations, 1000); // Update every second
|