document.addEventListener('DOMContentLoaded', function() {

    let startTime = localStorage.getItem('start_time');
    if (!startTime) {
      startTime = Date.now();
      localStorage.setItem('start_time', startTime);
    }

    function updateTimer() {
      const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
      displayTime(elapsedTime);
    }
  
    function displayTime(seconds) {
      const formattedTime = new Date(seconds * 1000).toISOString().substr(11, 8);
      document.getElementById('timer').textContent = formattedTime;
    }
  
    setInterval(updateTimer, 1000);
  
    window.addEventListener('beforeunload', function() {
      const elapsedTime = Math.floor((Date.now() - startTime) / 1000);
      localStorage.setItem('elapsed_time', elapsedTime);
    });
  });
  