Allow viewing yesterday's train
This can be achieved by selecting the date in the view train screen.
This commit is contained in:
parent
a6757f394a
commit
f1141b1e06
2 changed files with 13 additions and 3 deletions
2
sw.js
2
sw.js
|
@ -1,4 +1,4 @@
|
||||||
const VERSION = 'v10'
|
const VERSION = 'v11'
|
||||||
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`
|
||||||
|
|
|
@ -2,6 +2,7 @@ var trainNumber
|
||||||
var date
|
var date
|
||||||
var groupIndex = null
|
var groupIndex = null
|
||||||
|
|
||||||
|
var yesterday = false
|
||||||
var showKm = false
|
var showKm = false
|
||||||
|
|
||||||
var trainData = null
|
var trainData = null
|
||||||
|
@ -39,10 +40,12 @@ function onTrainData(data) {
|
||||||
dateHref.textContent = data.date
|
dateHref.textContent = data.date
|
||||||
dateHref.href = '#'
|
dateHref.href = '#'
|
||||||
dateHref.classList.add('no-a-custom')
|
dateHref.classList.add('no-a-custom')
|
||||||
// dateHref.classList.add('items', 'no-a-custom')
|
dateHref.classList.add('items', 'no-a-custom')
|
||||||
dateHref.addEventListener('click', function (e) {
|
dateHref.addEventListener('click', function (e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
// Implement date switcher
|
// Implement date switcher
|
||||||
|
yesterday = !yesterday
|
||||||
|
refresh()
|
||||||
})
|
})
|
||||||
|
|
||||||
document.getElementById('loading').classList.add('hidden')
|
document.getElementById('loading').classList.add('hidden')
|
||||||
|
@ -340,8 +343,15 @@ function refresh() {
|
||||||
refresh()
|
refresh()
|
||||||
}, timeout || 60000)
|
}, timeout || 60000)
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* @type {Date}
|
||||||
|
*/
|
||||||
|
var reqDate = date
|
||||||
|
if (yesterday) {
|
||||||
|
reqDate.setDate(reqDate.getDate() - 1)
|
||||||
|
}
|
||||||
return fetch(
|
return fetch(
|
||||||
`https://scraper.infotren.dcdev.ro/v3/trains/${trainNumber}?date=${date.getFullYear().toString()}-${(date.getMonth() + 1).toString().padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`,
|
`https://scraper.infotren.dcdev.ro/v3/trains/${trainNumber}?date=${reqDate.getFullYear().toString()}-${(reqDate.getMonth() + 1).toString().padStart(2, "0")}-${reqDate.getDate().toString().padStart(2, "0")}`,
|
||||||
{
|
{
|
||||||
cache: 'no-store',
|
cache: 'no-store',
|
||||||
},
|
},
|
||||||
|
|
Loading…
Add table
Reference in a new issue