|
|
@ -193,22 +193,36 @@ function onTrainData(data) { |
|
|
|
|
|
|
|
|
|
|
|
var refreshStopToken = null |
|
|
|
var refreshStopToken = null |
|
|
|
function refresh() { |
|
|
|
function refresh() { |
|
|
|
return fetch(`https://scraper.infotren.dcdev.ro/v2/train/${trainNumber}?date=${date.getFullYear().toString()}-${(date.getMonth() + 1).toString().padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`) |
|
|
|
function reschedule(timeout) { |
|
|
|
.then(function (response) { |
|
|
|
if (refreshStopToken != null) { |
|
|
|
return response.json() |
|
|
|
clearTimeout(refreshStopToken) |
|
|
|
}) |
|
|
|
} |
|
|
|
.then(function (response) { |
|
|
|
refreshStopToken = setTimeout(function () {
|
|
|
|
trainData = response |
|
|
|
refresh() |
|
|
|
onTrainData(response) |
|
|
|
}, timeout || 60000) |
|
|
|
}) |
|
|
|
} |
|
|
|
.then(function () { |
|
|
|
return fetch( |
|
|
|
if (refreshStopToken != null) { |
|
|
|
`https://scraper.infotren.dcdev.ro/v2/train/${trainNumber}?date=${date.getFullYear().toString()}-${(date.getMonth() + 1).toString().padStart(2, "0")}-${date.getDate().toString().padStart(2, "0")}`, |
|
|
|
clearTimeout(refreshStopToken) |
|
|
|
{ |
|
|
|
} |
|
|
|
cache: 'no-store', |
|
|
|
refreshStopToken = setTimeout(function () {
|
|
|
|
}, |
|
|
|
refresh() |
|
|
|
).then(function (response) { |
|
|
|
}, 60000) |
|
|
|
if (!response.ok) { |
|
|
|
}) |
|
|
|
// Check in 10 seconds if server returned error
|
|
|
|
|
|
|
|
reschedule(10000) |
|
|
|
|
|
|
|
return |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return response.json() |
|
|
|
|
|
|
|
}).then(function (response) { |
|
|
|
|
|
|
|
trainData = response |
|
|
|
|
|
|
|
onTrainData(response) |
|
|
|
|
|
|
|
}).then(function () { |
|
|
|
|
|
|
|
reschedule() |
|
|
|
|
|
|
|
}).catch(function (e) { |
|
|
|
|
|
|
|
// Check in 1 second if network error
|
|
|
|
|
|
|
|
reschedule(1000) |
|
|
|
|
|
|
|
throw e |
|
|
|
|
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
window.addEventListener('unload', function (e) { |
|
|
|
window.addEventListener('unload', function (e) { |
|
|
|