From 75cdfcf09a31a9d98f46dda1d0d908c3f4584452 Mon Sep 17 00:00:00 2001 From: Interitio Date: Mon, 3 Nov 2025 22:20:10 +1000 Subject: [PATCH] Add timer end checking --- timer.js | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/timer.js b/timer.js index b6494bc..f3a2ccf 100644 --- a/timer.js +++ b/timer.js @@ -8,6 +8,8 @@ class Timer { constructor(renderer, timer_data) { this.renderer = renderer; this.destroying = false; + this.ended = false; + //TEMP this.temptime = 15; @@ -34,7 +36,18 @@ class Timer { this.leaderboard = timer_data.leaderboard; } + check_ended() { + if (!this.ended && this.end_at < new Date()) { + this.ended = True; + this.renderer.finale(); + } + return this.ended; + } + render_time() { + if (this.check_ended()) { + return; + } this.renderer.render_time( //TEMP this.temptime @@ -43,6 +56,9 @@ class Timer { } render() { + if (this.check_ended()) { + return; + } // Render goal if (this.next_goal != null) { @@ -131,9 +147,9 @@ class TimerRenderer { this.scrollwraps = document.getElementsByClassName("scrollWrap") // Parent wrappers this.scrollboxes = [document.getElementById("GiftUserRow1"), - document.getElementById("GiftUserRow2"), - document.getElementById("GiftUserRow3"), - document.getElementById("ScrollWrapGoal")] + document.getElementById("GiftUserRow2"), + document.getElementById("GiftUserRow3"), + document.getElementById("ScrollWrapGoal")] // Leaderboard names this.userboxes = [this.topusers_user1_name, this.topusers_user2_name, this.topusers_user3_name] this.userdupeboxes = [this.topusers_userdupe1_name, this.topusers_userdupe2_name, this.topusers_userdupe3_name] @@ -146,12 +162,12 @@ class TimerRenderer { animate() { for (let i = 0; i < this.scrollboxes.length; i++) { - console.log('animate'); + console.log('animate'); // Check whether the itteration is a username or goal if (this.scrollboxes[i].id == 'ScrollWrapGoal') { // Check if element text overflows - if (this.goal_name.getBoundingClientRect().width > (this.scrollboxes[i].getBoundingClientRect().width * .85) ) { + if (this.goal_name.getBoundingClientRect().width > (this.scrollboxes[i].getBoundingClientRect().width * .85)) { // Toggle animation this.goal_name.classList.add("scrollAnim"); this.goal_namedupe.classList.add("scrollAnim"); @@ -170,7 +186,7 @@ class TimerRenderer { } else { // Check if element text overflows - if (this.userboxes[i].getBoundingClientRect().width > (this.scrollboxes[i].getBoundingClientRect().width * .75) ) { + if (this.userboxes[i].getBoundingClientRect().width > (this.scrollboxes[i].getBoundingClientRect().width * .75)) { // Toggle animation this.userboxes[i].classList.add("scrollAnim"); this.userdupeboxes[i].classList.add("scrollAnim"); @@ -270,10 +286,10 @@ class TimerRenderer { // Bitwise OR done to convert floats to integers if needed this.goal_progress.textContent = String(current | 0) + '/' + String(required | 0) - console.log('ratio' + current/required); - if (current/required > .02) { - console.log('%' + (current/required) * 100); - this.goal_bar.style.maskImage = `linear-gradient(to right, #55CBFF 0%, #55CBFF ${((current/required) - .02)*100}%, transparent ${(current/required)*100}%)`; + console.log('ratio' + current / required); + if (current / required > .02) { + console.log('%' + (current / required) * 100); + this.goal_bar.style.maskImage = `linear-gradient(to right, #55CBFF 0%, #55CBFF ${((current / required) - .02) * 100}%, transparent ${(current / required) * 100}%)`; } else { this.goal_bar.style.maskImage = `linear-gradient(to right, transparent 0%)`; }