Merge pull request #794 from twetech/timer-tracking-remember-manual-changes

Update timer to remember manual edits
This commit is contained in:
Johnny 2023-10-31 10:26:57 -04:00 committed by GitHub
commit 4ab38b42f8
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 21 additions and 0 deletions

View File

@ -99,6 +99,27 @@
}
}
function updateTimeFromInput() {
const hours = parseInt(document.getElementById("hours").value, 10) || 0;
const minutes = parseInt(document.getElementById("minutes").value, 10) || 0;
const seconds = parseInt(document.getElementById("seconds").value, 10) || 0;
elapsedSecs = (hours * 3600) + (minutes * 60) + seconds;
// Update local storage so the manually entered time is retained even if the page is reloaded.
if (!timerInterval) {
localStorage.setItem(getLocalStorageKey("pausedTime"), elapsedSecs.toString());
} else {
const newStartTime = Date.now() - (elapsedSecs * 1000);
localStorage.setItem(getLocalStorageKey("startTime"), newStartTime.toString());
localStorage.removeItem(getLocalStorageKey("pausedTime"));
}
}
document.getElementById("hours").addEventListener('change', updateTimeFromInput);
document.getElementById("minutes").addEventListener('change', updateTimeFromInput);
document.getElementById("seconds").addEventListener('change', updateTimeFromInput);
document.getElementById("hours").addEventListener('focus', handleInputFocus);
document.getElementById("minutes").addEventListener('focus', handleInputFocus);
document.getElementById("seconds").addEventListener('focus', handleInputFocus);