Skip to content

Commit

Permalink
Shortened "time till" code
Browse files Browse the repository at this point in the history
  • Loading branch information
Brelee2222 committed Aug 12, 2024
1 parent 4280fad commit cd78081
Showing 1 changed file with 8 additions and 34 deletions.
42 changes: 8 additions & 34 deletions src/frontend/dash/circlePacker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,41 +138,15 @@ export class ClockCircle extends Circle{
}
(async () => {
let arrivals = await getArrivals()
let timeElemsWest = document.querySelectorAll('.bustime.west')
let timeElemsEast = document.querySelectorAll('.bustime.east')

let minutesTillEastFirst = Math.max(0,Math.round((arrivals[busSigns[0]][0] - Date.now())/1000/60));
timeElemsEast[0].innerHTML = minutesTillEastFirst + ' min'
if(minutesTillEastFirst <= 5) {
timeElemsEast[0].classList.add('soonish')
} else {
timeElemsEast[0].classList.remove('soonish')
}

let minutesTillEastSecond = Math.max(0,Math.round((arrivals[busSigns[0]][1] - Date.now())/1000/60));
timeElemsEast[1].innerHTML = minutesTillEastSecond + '&nbsp;min'
if(minutesTillEastSecond <= 5) {
timeElemsEast[1].classList.add('soonish')
} else {
timeElemsEast[1].classList.remove('soonish')
}

let minutesTillWestFirst = Math.max(0,Math.round((arrivals[busSigns[1]][0] - Date.now())/1000/60));
timeElemsWest[0].innerHTML = minutesTillWestFirst + '&nbsp;min'
if(minutesTillEastFirst <= 5) {
timeElemsWest[0].classList.add('soonish')
} else {
timeElemsWest[0].classList.remove('soonish')
}

let minutesTillWestSecond = Math.max(0,Math.round((arrivals[busSigns[1]][1] - Date.now())/1000/60));
timeElemsWest[1].innerHTML = minutesTillWestSecond + '&nbsp;min'
if(minutesTillWestSecond <= 5) {
timeElemsWest[1].classList.add('soonish')
} else {
timeElemsWest[1].classList.remove('soonish')
const timeElems = [];
document.querySelectorAll('.bustime.east').forEach(timeElems.push);
document.querySelectorAll('.bustime.west').forEach(timeElems.push);

for(let busSignIndex = 0; busSignIndex < timeElems.length; busSignIndex++) {
let minutesTill = Math.max(0,Math.round((arrivals[busSigns[busSignIndex >> 1]][busSignIndex & 1] - Date.now())/1000/60));
timeElems[0].innerHTML = minutesTill + '&nbsp;min'
timeElems[0].classList[minutesTill <= 5 ? "add" : "remove"]("soonish")
}

})();
},
15000);
Expand Down

0 comments on commit cd78081

Please sign in to comment.