From 1ecd0e074304055f4186b5ac91c6fb7e6647d391 Mon Sep 17 00:00:00 2001 From: NicholasJohansan Date: Sun, 15 Jan 2023 08:54:09 +0800 Subject: [PATCH] Improve time left counter --- src/popup/js/time-left.js | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/popup/js/time-left.js b/src/popup/js/time-left.js index a418075..e99bfa6 100644 --- a/src/popup/js/time-left.js +++ b/src/popup/js/time-left.js @@ -8,7 +8,7 @@ function millisToMinutesAndSeconds(millis) { return minutes + ":" + (seconds < 10 ? '0' : '') + seconds; } -setInterval(async () => { +const runTimeLeftUpdate = async () => { const alarm = await browser.alarms.get("Breaks"); if (alarm) { console.log("hello"); @@ -16,5 +16,10 @@ setInterval(async () => { } if (timeLeft - 1000 >= 0) { timeLeftValue.textContent = millisToMinutesAndSeconds(timeLeft); + } else { + timeLeftValue.textContent = "disabled" } -}, 1000); \ No newline at end of file + setTimeout(runTimeLeftUpdate, 1000); +}; + +runTimeLeftUpdate(); \ No newline at end of file