Browse Source

Manipulate history when viewing yesterday's train

master
Kenneth Bruen 2 years ago
parent
commit
708f25ce83
Signed by: kbruen
GPG Key ID: C1980A470C3EE5B1
  1. 2
      sw.js
  2. 18
      view-train.js

2
sw.js

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

18
view-train.js

@ -89,6 +89,16 @@ function onTrainData(data, fetchDate) {
e.preventDefault() e.preventDefault()
// Implement date switcher // Implement date switcher
yesterday = !yesterday 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() refresh()
}) })
@ -495,7 +505,13 @@ function rsk() {
} }
window.addEventListener('popstate', function (e) { window.addEventListener('popstate', function (e) {
groupIndex = null if (yesterday) {
yesterday = false
trainData = null
}
else {
groupIndex = null
}
if (trainData) { if (trainData) {
onTrainData(trainData) onTrainData(trainData)
} }

Loading…
Cancel
Save