Manipulate history when viewing yesterday's train

This commit is contained in:
Kenneth Bruen 2023-03-17 03:16:51 +01:00
parent 0833765a84
commit 708f25ce83
Signed by: kbruen
GPG key ID: C1980A470C3EE5B1
2 changed files with 18 additions and 2 deletions

2
sw.js
View file

@ -1,4 +1,4 @@
const VERSION = 'v33'
const VERSION = 'v34'
const API_ORIGIN = 'https://scraper.infotren.dcdev.ro/'
const API_TRAINS = `${API_ORIGIN}v3/trains`
const API_STATIONS = `${API_ORIGIN}v3/stations`

View file

@ -89,6 +89,16 @@ function onTrainData(data, fetchDate) {
e.preventDefault()
// Implement date switcher
yesterday = !yesterday
if (!yesterday) {
history.back()
}
else {
const yesterdayUrl = new URL(location.href)
const newDate = new Date(date.getTime())
newDate.setDate(newDate.getDate() - 1)
yesterdayUrl.searchParams.set('date', newDate.toISOString())
history.pushState('', '', yesterdayUrl)
}
refresh()
})
@ -495,7 +505,13 @@ function rsk() {
}
window.addEventListener('popstate', function (e) {
if (yesterday) {
yesterday = false
trainData = null
}
else {
groupIndex = null
}
if (trainData) {
onTrainData(trainData)
}