|
|
|
@ -4,6 +4,7 @@ var date
|
|
|
|
|
var showKm = false |
|
|
|
|
|
|
|
|
|
var trainData = null |
|
|
|
|
var lastSuccessfulFetch = null |
|
|
|
|
|
|
|
|
|
function onTrainData(data) { |
|
|
|
|
var title = document.getElementsByTagName('h1')[0] |
|
|
|
@ -186,11 +187,13 @@ function onTrainData(data) {
|
|
|
|
|
stationPlatform.classList.add('thi', 'platform') |
|
|
|
|
} |
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
lastSuccessfulFetch = new Date() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
var refreshStopToken = null |
|
|
|
|
function refresh() { |
|
|
|
|
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")}`) |
|
|
|
|
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")}`) |
|
|
|
|
.then(function (response) { |
|
|
|
|
return response.json() |
|
|
|
|
}) |
|
|
|
@ -277,4 +280,33 @@ window.addEventListener('load', function (e) {
|
|
|
|
|
}) |
|
|
|
|
|
|
|
|
|
refresh() |
|
|
|
|
|
|
|
|
|
setInterval(function () { |
|
|
|
|
if (!lastSuccessfulFetch) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
var millis = new Date() - lastSuccessfulFetch |
|
|
|
|
var secs = Math.floor(millis / 1000) |
|
|
|
|
|
|
|
|
|
var timeStr = '' |
|
|
|
|
if (secs / 3600 >= 1) { |
|
|
|
|
timeStr += `${Math.floor(secs / 3600)}h` |
|
|
|
|
secs = secs % 3600 |
|
|
|
|
} |
|
|
|
|
if (secs / 60 >= 1) { |
|
|
|
|
timeStr += `${Math.floor(secs / 60)}m` |
|
|
|
|
secs = secs % 60 |
|
|
|
|
} |
|
|
|
|
if (secs >= 1) { |
|
|
|
|
timeStr += `${Math.floor(secs)}s` |
|
|
|
|
} |
|
|
|
|
if (!timeStr) { |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
document.querySelectorAll('.lsk').forEach(function (elem) { |
|
|
|
|
elem.textContent = `Last refreshed ${timeStr} ago` |
|
|
|
|
elem.classList.add('last-refreshed') |
|
|
|
|
}) |
|
|
|
|
}, 500) |
|
|
|
|
}) |
|
|
|
|