Improve timer interval display (#3096) (#3100)

* Improve update interval of timer display

Timer calculation frequency increased and aligned with new card apparition.

* Update CONTRIBUTORS

* Update timer interval to 0.333 sec

* Restore timer to 1 sec

- Restoring timer to 1sec value as it is not necessary to increase the frequency.

- Adding a time update directy after new card is displayed so that the timer display immediatly restarts to 0.
This commit is contained in:
Antoine Q 2024-03-31 08:49:16 +02:00 committed by GitHub
parent 111f3bd138
commit 32c129656e
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 15 additions and 9 deletions

View file

@ -168,6 +168,7 @@ Arbyste <arbyste@outlook.com>
Vasll <github.com/vasll>
laalsaas <laalsaas@systemli.org>
ijqq <ijqq@protonmail.ch>
AntoineQ1 <https://github.com/AntoineQ1>
********************
The text of the 3 clause BSD license follows:

View file

@ -9,15 +9,6 @@ let time: number; // set in python code
let timerStopped = false;
let maxTime = 0;
document.addEventListener("DOMContentLoaded", () => {
updateTime();
setInterval(function() {
if (!timerStopped) {
time += 1;
updateTime();
}
}, 1000);
});
function updateTime(): void {
const timeNode = document.getElementById("time");
@ -38,10 +29,24 @@ function updateTime(): void {
}
}
let intervalId: number | undefined;
function showQuestion(txt: string, maxTime_: number): void {
showAnswer(txt);
time = 0;
maxTime = maxTime_;
updateTime();
if (intervalId !== undefined) {
clearInterval(intervalId);
}
intervalId = setInterval(function() {
if (!timerStopped) {
time += 1;
updateTime();
}
}, 1000);
}
function showAnswer(txt: string, stopTimer = false): void {