From 6cd1b574c2074323231dbb134a6098dadae0ad26 Mon Sep 17 00:00:00 2001 From: Dorian Zedler Date: Thu, 12 May 2022 17:28:59 +0200 Subject: [PATCH] Feat: auto-hide banners, don't show hours when zero, add version --- src/index.php | 1 + src/static/js/synced-timer.js | 36 ++++++++++++++++++++++++++++------- src/theme.php | 22 ++++++++++++++++----- src/version.php | 4 ++++ 4 files changed, 51 insertions(+), 12 deletions(-) create mode 100644 src/version.php diff --git a/src/index.php b/src/index.php index 83f308b..3c799c7 100644 --- a/src/index.php +++ b/src/index.php @@ -4,6 +4,7 @@ define('L_EXEC', true); require_once './theme.php'; require_once './strings.php'; require_once './storageHelper.php'; +require_once './version.php'; class SyncedTimer { diff --git a/src/static/js/synced-timer.js b/src/static/js/synced-timer.js index ee904df..328a293 100644 --- a/src/static/js/synced-timer.js +++ b/src/static/js/synced-timer.js @@ -41,20 +41,29 @@ document.addEventListener('alpine:init' , () => { playTimerSound(remaningSeconds); }, 100) - setInterval(() => { - this.requestStartedAt = Date.now(); - fetch(`/api/${username}`) + this.scheduleNextRequest() + }, + + scheduleNextRequest() { + setTimeout(() => { + let requestUrl; + const requestId = Date.now(); + fetch(`/api/${username}#${requestId}`) .then((response) => { - this.requestEndedAt = Date.now() + requestUrl = response.url return response.json() }) .then((data) => { if(data && data.status === 200) { - const requestDuration = this.requestEndedAt - this.requestStartedAt; - this.timeOffsetToServer = this.requestEndedAt - data.data.currentServerTime + (requestDuration / 2); + const performanceEntry = performance.getEntriesByName(`${requestUrl}#${requestId}`)[0]; + console.log(performanceEntry) + const requestDuration = performanceEntry.responseEnd - performanceEntry.requestStart; + this.timeOffsetToServer = performanceEntry.responseEnd - data.data.currentServerTime + (requestDuration / 2); + console.log(requestDuration, "offset: ", this.timeOffsetToServer) } - + this.lastResponse = data + this.scheduleNextRequest() }); }, 1000) } @@ -124,6 +133,15 @@ document.addEventListener('alpine:init' , () => { } } }) + + Alpine.store("banners", { + hide: false, + init() { + setTimeout(() => { + this.hide = true + }, 10000) + } + }) }) document.addEventListener('alpine:initialized', () => { @@ -141,6 +159,10 @@ function getTimerText(remaningSeconds) { var remaningMinutes = zeroPad(parseInt(remaningSeconds / 60) % 60, 2) var remaningSeconds = zeroPad(remaningSeconds % 60, 2) + if(parseInt(remaningHours) === 0) { + return " " + remaningMinutes + ":" + remaningSeconds + " " + } + return remaningHours + ":" + remaningMinutes + ":" + remaningSeconds } diff --git a/src/theme.php b/src/theme.php index 01bebd0..ba93a5c 100644 --- a/src/theme.php +++ b/src/theme.php @@ -190,8 +190,16 @@ class LandingpageTheme
+ + + + + + + + -