add paranoiaOffset

This commit is contained in:
2023-12-02 14:08:54 +01:00
parent 754893252e
commit f575301a6d
3 changed files with 35 additions and 2 deletions
+5
View File
@@ -17,6 +17,11 @@
<h3 class="location-container">The <span id="location">...</span> Championship</h3> <h3 class="location-container">The <span id="location">...</span> Championship</h3>
<p class="championship">at <span id="time">00:00</span></p> <p class="championship">at <span id="time">00:00</span></p>
<p class="remaining">Remaining: <span id="timer">00:00:00</span></p> <p class="remaining">Remaining: <span id="timer">00:00:00</span></p>
<details>
<summary>More</summary>
<p class="paranoia-disclaimer">Make my timers shorter by <input id="paranoia" type="number" step="1" value="2"></input></p>
</details>
</div> </div>
</div> </div>
+8
View File
@@ -18,4 +18,12 @@ export default class Transform {
static time(time) { static time(time) {
return Math.floor(time/60).toString().padStart(2, '0') + ":" + (time % 60).toString().padStart(2, '0') return Math.floor(time/60).toString().padStart(2, '0') + ":" + (time % 60).toString().padStart(2, '0')
} }
static stopAtZero(number) {
if (number > 0) {
return number
}
return 0
}
} }
+22 -2
View File
@@ -9,6 +9,8 @@ export default class UI {
constructor(rootObject) { constructor(rootObject) {
this.rootObject = rootObject this.rootObject = rootObject
this.savedParanoiaOffset = localStorage.getItem('paranoiaOffset') || 2
this.setParanoiaOffset(this.savedParanoiaOffset)
this.loadChampionships() this.loadChampionships()
this.start() // auto-start, might need some more thought this.start() // auto-start, might need some more thought
} }
@@ -17,6 +19,19 @@ export default class UI {
UI.instance = new UI(window.document) UI.instance = new UI(window.document)
} }
get paranoiaOffset() {
let currentParanoiaOffset = this.rootObject.getElementById('paranoia').value
if (this.savedParanoiaOffset != currentParanoiaOffset) {
localStorage.setItem('paranoiaOffset', currentParanoiaOffset)
}
return currentParanoiaOffset
}
setParanoiaOffset(value) {
this.rootObject.getElementById('paranoia').value = value
}
loadResponseIntoData(response) { loadResponseIntoData(response) {
response.json().then(Data.init) response.json().then(Data.init)
} }
@@ -54,8 +69,13 @@ export default class UI {
} }
updateTimer(next) { updateTimer(next) {
let remaining = Transform.time(next.remaining) + ":" + Day.secondsUntilFullMinute let remaining = next.remaining - this.paranoiaOffset
this.rootObject.getElementById('timer').innerHTML = remaining let formattedRemaining = '00:00:00'
if (remaining >= 0) {
formattedRemaining = Transform.time(remaining) + ":" + Day.secondsUntilFullMinute
}
this.rootObject.getElementById('timer').innerHTML = formattedRemaining
this.rootObject.title = `${remaining} - ${next.location} - SSO Timer` this.rootObject.title = `${remaining} - ${next.location} - SSO Timer`
} }