UpcomingAd is now formatted in mm:ss

This commit is contained in:
nuttylmao
2025-06-05 06:23:57 +10:00
parent 51e902b5ff
commit c9121947cc
+18 -2
View File
@@ -277,7 +277,7 @@ function UpcomingAdWarning(warningSeconds) {
var timerThingy = setInterval(function () { var timerThingy = setInterval(function () {
startingTime--; startingTime--;
countdownLabel.innerText = startingTime; countdownLabel.innerText = formatTime(startingTime);
if (startingTime == 0) { if (startingTime == 0) {
clearInterval(timerThingy); clearInterval(timerThingy);
upcomingAdWarningContainer.style.right = -width + "px"; upcomingAdWarningContainer.style.right = -width + "px";
@@ -352,6 +352,22 @@ function IsNullOrWhitespace(str) {
return /^\s*$/.test(str); return /^\s*$/.test(str);
} }
function formatTime(seconds) {
seconds = Math.floor(seconds); // Round down to nearest whole second
if (seconds < 60) {
return `${seconds}`;
}
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
// Pad seconds with a leading zero if less than 10
const paddedSecs = secs.toString().padStart(2, '0');
return `${mins}:${paddedSecs}`;
}
//////////////////// ////////////////////
// TEST FUNCTIONS // // TEST FUNCTIONS //
//////////////////// ////////////////////
@@ -371,7 +387,7 @@ function testAd() {
} }
function testUpcomingAdWarning() { function testUpcomingAdWarning() {
UpcomingAdWarning(10); UpcomingAdWarning(warningSeconds);
} }