mirror of
https://codeberg.org/kbruen/kai.infotren.git
synced 2025-06-19 10:42:30 +03:00
Compare commits
No commits in common. "7645effd5fd37c9f10052544a7f823bff1771e54" and "04e2019afe3cb250a8d605e93e990c5d506a87b1" have entirely different histories.
7645effd5f
...
04e2019afe
7 changed files with 12 additions and 125 deletions
6
base.css
6
base.css
|
@ -255,12 +255,6 @@ body {
|
||||||
font-family: -apple-system, BlinkMacSystemFont, Ubuntu, 'Segoe UI', 'Roboto', Sans-Serif, sans-serif;
|
font-family: -apple-system, BlinkMacSystemFont, Ubuntu, 'Segoe UI', 'Roboto', Sans-Serif, sans-serif;
|
||||||
}
|
}
|
||||||
|
|
||||||
pre {
|
|
||||||
margin: 0;
|
|
||||||
display: inline;
|
|
||||||
font-family: 'Martian Mono', Menlo, Consolas, Monaco, Liberation Mono, Lucida Console, monospace;
|
|
||||||
}
|
|
||||||
|
|
||||||
.tabs {
|
.tabs {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: row;
|
flex-direction: row;
|
||||||
|
|
|
@ -12,8 +12,6 @@
|
||||||
|
|
||||||
<script src="/common/worker.js"></script>
|
<script src="/common/worker.js"></script>
|
||||||
<script src="/common/items.js"></script>
|
<script src="/common/items.js"></script>
|
||||||
<script src="/common/trainId.js"></script>
|
|
||||||
<script src="index.js"></script>
|
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<h1>InfoTren</h1>
|
<h1>InfoTren</h1>
|
||||||
|
@ -21,8 +19,8 @@
|
||||||
<div class="content">
|
<div class="content">
|
||||||
<ul>
|
<ul>
|
||||||
<li><a class="items disabled" href="">Train routes</a></li>
|
<li><a class="items disabled" href="">Train routes</a></li>
|
||||||
<li id="my-train-li"><a class="items" href="train.html">My train</a></li>
|
<li><a class="items" href="train.html">My train</a></li>
|
||||||
<li id="station-arr-dep-li"><a class="items" href="station.html">Station departures/arrivals</a></li>
|
<li><a class="items" href="station.html">Station departures/arrivals</a></li>
|
||||||
<li><a class="items" href="about.html">About</a></li>
|
<li><a class="items" href="about.html">About</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
|
|
58
index.js
58
index.js
|
@ -1,58 +0,0 @@
|
||||||
window.addEventListener('load', function (e) {
|
|
||||||
if (window.localStorage) {
|
|
||||||
var recentViewTrain = localStorage.getItem('recent/view-train')
|
|
||||||
if (recentViewTrain) {
|
|
||||||
/**
|
|
||||||
* @property {string} trainNumber
|
|
||||||
* @property {string} date
|
|
||||||
* @property {string} $addDate
|
|
||||||
* @property {string | undefined} groupIndex
|
|
||||||
*/
|
|
||||||
recentViewTrain = JSON.parse(recentViewTrain)
|
|
||||||
var addDate = new Date(recentViewTrain.$addDate)
|
|
||||||
addDate.setHours(addDate.getHours() + 2) // store recents for 2 hours
|
|
||||||
if (addDate.getTime() > Date.now()) {
|
|
||||||
var recentViewTrainLi = document.createElement('li')
|
|
||||||
var recentViewTrainLink = document.createElement('a')
|
|
||||||
recentViewTrainLi.appendChild(recentViewTrainLink)
|
|
||||||
var recentViewTrainLinkUrl = new URL('/view-train.html', window.location.origin)
|
|
||||||
recentViewTrainLinkUrl.searchParams.append('train', recentViewTrain.trainNumber)
|
|
||||||
recentViewTrainLinkUrl.searchParams.append('date', recentViewTrain.date)
|
|
||||||
if (recentViewTrain.groupIndex) {
|
|
||||||
recentViewTrainLinkUrl.searchParams.append('groupIndex', recentViewTrain.groupIndex)
|
|
||||||
}
|
|
||||||
recentViewTrainLink.href = recentViewTrainLinkUrl.toString()
|
|
||||||
recentViewTrainLink.classList.add('items')
|
|
||||||
recentViewTrainLink.innerText = `Recent train: ${recentViewTrain.trainNumber}`
|
|
||||||
|
|
||||||
fetch(`https://scraper.infotren.dcdev.ro/v3/trains/${recentViewTrain.trainNumber}?date=${recentViewTrain.date}`)
|
|
||||||
.then(function (result) {
|
|
||||||
if (result.ok) {
|
|
||||||
return result.json()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.then(function (result) {
|
|
||||||
recentViewTrainLink.innerText = 'Recent train: '
|
|
||||||
trainIdSpan(result.rank, result.number, recentViewTrainLink)
|
|
||||||
if (recentViewTrain.groupIndex !== undefined || result.groups.length === 1) {
|
|
||||||
var group = result.groups[recentViewTrain.groupIndex || 0]
|
|
||||||
if (group.status) {
|
|
||||||
if (group.status.delay === 0) {
|
|
||||||
recentViewTrainLink.appendChild(document.createTextNode(" (on time)"))
|
|
||||||
}
|
|
||||||
else if (group.status.delay > 0) {
|
|
||||||
recentViewTrainLink.appendChild(document.createTextNode(` (${group.status.delay} min late)`))
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
recentViewTrainLink.appendChild(document.createTextNode(` (${-group.status.delay} min early)`))
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
var myTrainLi = document.getElementById("my-train-li")
|
|
||||||
myTrainLi.parentNode.insertBefore(recentViewTrainLi, myTrainLi.nextSibling)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
})
|
|
4
sw.js
4
sw.js
|
@ -1,4 +1,4 @@
|
||||||
const VERSION = 'v24'
|
const VERSION = 'v20'
|
||||||
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`
|
||||||
|
@ -22,10 +22,8 @@ const CACHE_FIRST = [
|
||||||
|
|
||||||
// Pages
|
// Pages
|
||||||
'/index.html',
|
'/index.html',
|
||||||
'/index.js',
|
|
||||||
|
|
||||||
'/about.html',
|
'/about.html',
|
||||||
'/about.js',
|
|
||||||
|
|
||||||
'/train.html',
|
'/train.html',
|
||||||
'/train.js',
|
'/train.js',
|
||||||
|
|
|
@ -39,9 +39,7 @@ function onStationData(data) {
|
||||||
var timeDiv = document.createElement('p')
|
var timeDiv = document.createElement('p')
|
||||||
trainItem.appendChild(timeDiv)
|
trainItem.appendChild(timeDiv)
|
||||||
timeDiv.classList.add('pri', 'time')
|
timeDiv.classList.add('pri', 'time')
|
||||||
var timeDivPre = document.createElement('pre')
|
timeDiv.textContent = new Date(train.time).toLocaleTimeString([], { 'hour': '2-digit', 'minute': '2-digit' })
|
||||||
timeDiv.appendChild(timeDivPre)
|
|
||||||
timeDivPre.textContent = new Date(train.time).toLocaleTimeString([], { 'hour': '2-digit', 'minute': '2-digit' })
|
|
||||||
|
|
||||||
if (train.status && train.status.delay != 0) {
|
if (train.status && train.status.delay != 0) {
|
||||||
var delayDiv = document.createElement('p')
|
var delayDiv = document.createElement('p')
|
||||||
|
@ -63,24 +61,20 @@ function onStationData(data) {
|
||||||
|
|
||||||
var rankDiv = document.createElement('p')
|
var rankDiv = document.createElement('p')
|
||||||
trainItem.appendChild(rankDiv)
|
trainItem.appendChild(rankDiv)
|
||||||
|
rankDiv.textContent = train.train.rank
|
||||||
rankDiv.classList.add('sec', 'rank', train.train.rank)
|
rankDiv.classList.add('sec', 'rank', train.train.rank)
|
||||||
var rankDivPre = document.createElement('pre')
|
|
||||||
rankDiv.appendChild(rankDivPre)
|
|
||||||
rankDivPre.textContent = train.train.rank
|
|
||||||
|
|
||||||
var trainDiv = document.createElement('p')
|
var trainDiv = document.createElement('p')
|
||||||
trainItem.appendChild(trainDiv)
|
trainItem.appendChild(trainDiv)
|
||||||
trainDiv.classList.add('pri', 'train')
|
trainDiv.classList.add('pri', 'train')
|
||||||
var trainDivHref = document.createElement('a')
|
var trainDivHref = document.createElement('a')
|
||||||
trainDiv.appendChild(trainDivHref)
|
trainDiv.appendChild(trainDivHref)
|
||||||
|
trainDivHref.textContent = train.train.number
|
||||||
trainDivHref.classList.add('no-a-custom')
|
trainDivHref.classList.add('no-a-custom')
|
||||||
var trainUrl = new URL('/view-train.html', window.location.origin)
|
var trainUrl = new URL('/view-train.html', window.location.origin)
|
||||||
trainUrl.searchParams.append('train', train.train.number)
|
trainUrl.searchParams.append('train', train.train.number)
|
||||||
trainUrl.searchParams.append('date', train.train.departureDate)
|
trainUrl.searchParams.append('date', train.train.departureDate)
|
||||||
trainDivHref.href = trainUrl.toString()
|
trainDivHref.href = trainUrl.toString()
|
||||||
var trainDivHrefPre = document.createElement('pre')
|
|
||||||
trainDivHref.appendChild(trainDivHrefPre)
|
|
||||||
trainDivHrefPre.textContent = train.train.number
|
|
||||||
|
|
||||||
var terminusDiv = document.createElement('p')
|
var terminusDiv = document.createElement('p')
|
||||||
trainItem.appendChild(terminusDiv)
|
trainItem.appendChild(terminusDiv)
|
||||||
|
@ -91,9 +85,7 @@ function onStationData(data) {
|
||||||
var platformDiv = document.createElement('div')
|
var platformDiv = document.createElement('div')
|
||||||
trainItem.appendChild(platformDiv)
|
trainItem.appendChild(platformDiv)
|
||||||
platformDiv.classList.add('thi', 'platform')
|
platformDiv.classList.add('thi', 'platform')
|
||||||
var platformDivPre = document.createElement('pre')
|
platformDiv.textContent = train.status.platform
|
||||||
platformDiv.appendChild(platformDivPre)
|
|
||||||
platformDivPre.textContent = train.status.platform
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (train.status && train.status.cancelled) {
|
if (train.status && train.status.cancelled) {
|
||||||
|
@ -209,12 +201,6 @@ window.addEventListener('load', function (e) {
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
if (navigator.canShare && navigator.canShare({ url: '' })) {
|
|
||||||
document.getElementById('title').addEventListener('click', function () {
|
|
||||||
navigator.share({ url: '' });
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
refresh()
|
refresh()
|
||||||
|
|
||||||
setInterval(function () {
|
setInterval(function () {
|
||||||
|
|
|
@ -64,7 +64,7 @@
|
||||||
align-items: flex-end;
|
align-items: flex-end;
|
||||||
}
|
}
|
||||||
|
|
||||||
.stationItem .arrival, .stationItem .departure {
|
.stationItem .arrival, .station .departure {
|
||||||
align-self: center;
|
align-self: center;
|
||||||
|
|
||||||
display: flex;
|
display: flex;
|
||||||
|
|
|
@ -129,14 +129,6 @@ function onTrainData(data, fetchDate) {
|
||||||
function onAction(e) {
|
function onAction(e) {
|
||||||
var url = new URL(window.location.toString())
|
var url = new URL(window.location.toString())
|
||||||
groupIndex = i
|
groupIndex = i
|
||||||
if (window.localStorage) {
|
|
||||||
localStorage.setItem('recent/view-train', JSON.stringify({
|
|
||||||
trainNumber: trainNumber,
|
|
||||||
date: date.toISOString(),
|
|
||||||
groupIndex: groupIndex,
|
|
||||||
$addDate: new Date().toISOString(),
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
url.searchParams.append('groupIndex', groupIndex)
|
url.searchParams.append('groupIndex', groupIndex)
|
||||||
window.history.pushState({'groupIndex': groupIndex}, '', url.toString( ))
|
window.history.pushState({'groupIndex': groupIndex}, '', url.toString( ))
|
||||||
onTrainData(data)
|
onTrainData(data)
|
||||||
|
@ -293,7 +285,7 @@ function onTrainData(data, fetchDate) {
|
||||||
|
|
||||||
var originalArr = document.createElement('p')
|
var originalArr = document.createElement('p')
|
||||||
stationArrival.appendChild(originalArr)
|
stationArrival.appendChild(originalArr)
|
||||||
var originalArrSpan = document.createElement('pre')
|
var originalArrSpan = document.createElement('span')
|
||||||
originalArr.appendChild(originalArrSpan)
|
originalArr.appendChild(originalArrSpan)
|
||||||
var arrDate = new Date(station.arrival.scheduleTime)
|
var arrDate = new Date(station.arrival.scheduleTime)
|
||||||
originalArrSpan.textContent = arrDate.toLocaleTimeString([], { 'hour': '2-digit', 'minute': '2-digit' })
|
originalArrSpan.textContent = arrDate.toLocaleTimeString([], { 'hour': '2-digit', 'minute': '2-digit' })
|
||||||
|
@ -311,13 +303,11 @@ function onTrainData(data, fetchDate) {
|
||||||
var actualArr = document.createElement('p')
|
var actualArr = document.createElement('p')
|
||||||
stationArrival.appendChild(actualArr)
|
stationArrival.appendChild(actualArr)
|
||||||
arrDate.setMinutes(arrDate.getMinutes() + station.arrival.status.delay)
|
arrDate.setMinutes(arrDate.getMinutes() + station.arrival.status.delay)
|
||||||
|
actualArr.textContent = arrDate.toLocaleTimeString([], { 'hour': '2-digit', 'minute': '2-digit' })
|
||||||
actualArr.classList.add('pri', station.arrival.status.delay > 0 ? 'late' : 'early')
|
actualArr.classList.add('pri', station.arrival.status.delay > 0 ? 'late' : 'early')
|
||||||
if (!station.arrival.status.real) {
|
if (!station.arrival.status.real) {
|
||||||
actualArr.classList.add('not-real')
|
actualArr.classList.add('not-real')
|
||||||
}
|
}
|
||||||
var actualArrPre = document.createElement('pre')
|
|
||||||
actualArr.appendChild(actualArrPre)
|
|
||||||
actualArrPre.textContent = arrDate.toLocaleTimeString([], { 'hour': '2-digit', 'minute': '2-digit' })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -329,7 +319,7 @@ function onTrainData(data, fetchDate) {
|
||||||
var originalDep = document.createElement('p')
|
var originalDep = document.createElement('p')
|
||||||
stationDeparture.appendChild(originalDep)
|
stationDeparture.appendChild(originalDep)
|
||||||
var depDate = new Date(station.departure.scheduleTime)
|
var depDate = new Date(station.departure.scheduleTime)
|
||||||
var originalDepSpan = document.createElement('pre')
|
var originalDepSpan = document.createElement('span')
|
||||||
originalDep.appendChild(originalDepSpan)
|
originalDep.appendChild(originalDepSpan)
|
||||||
originalDepSpan.textContent = depDate.toLocaleTimeString([], { 'hour': '2-digit', 'minute': '2-digit' })
|
originalDepSpan.textContent = depDate.toLocaleTimeString([], { 'hour': '2-digit', 'minute': '2-digit' })
|
||||||
originalDep.classList.add('pri')
|
originalDep.classList.add('pri')
|
||||||
|
@ -346,13 +336,11 @@ function onTrainData(data, fetchDate) {
|
||||||
var actualDep = document.createElement('p')
|
var actualDep = document.createElement('p')
|
||||||
stationDeparture.appendChild(actualDep)
|
stationDeparture.appendChild(actualDep)
|
||||||
depDate.setMinutes(depDate.getMinutes() + station.departure.status.delay)
|
depDate.setMinutes(depDate.getMinutes() + station.departure.status.delay)
|
||||||
|
actualDep.textContent = depDate.toLocaleTimeString([], { 'hour': '2-digit', 'minute': '2-digit' })
|
||||||
actualDep.classList.add('pri', station.departure.status.delay > 0 ? 'late' : 'early')
|
actualDep.classList.add('pri', station.departure.status.delay > 0 ? 'late' : 'early')
|
||||||
if (!station.departure.status.real) {
|
if (!station.departure.status.real) {
|
||||||
actualDep.classList.add('not-real')
|
actualDep.classList.add('not-real')
|
||||||
}
|
}
|
||||||
var actualDepPre = document.createElement('pre')
|
|
||||||
actualDep.appendChild(actualDepPre)
|
|
||||||
actualDepPre.textContent = depDate.toLocaleTimeString([], { 'hour': '2-digit', 'minute': '2-digit' })
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -520,31 +508,12 @@ window.addEventListener('load', function (e) {
|
||||||
date = sp.has('date') ? new Date(sp.get('date')) : new Date()
|
date = sp.has('date') ? new Date(sp.get('date')) : new Date()
|
||||||
groupIndex = sp.has('groupIndex') ? parseInt(sp.get('groupIndex')) : null
|
groupIndex = sp.has('groupIndex') ? parseInt(sp.get('groupIndex')) : null
|
||||||
|
|
||||||
if (window.localStorage) {
|
|
||||||
var oldRecent = localStorage.getItem('recent/view-train')
|
|
||||||
if (oldRecent) {
|
|
||||||
oldRecent = JSON.parse(oldRecent)
|
|
||||||
}
|
|
||||||
localStorage.setItem('recent/view-train', JSON.stringify({
|
|
||||||
trainNumber: trainNumber,
|
|
||||||
date: date.toISOString(),
|
|
||||||
groupIndex: oldRecent && oldRecent.trainNumber === trainNumber ? oldRecent.groupIndex : undefined,
|
|
||||||
$addDate: new Date().toISOString(),
|
|
||||||
}))
|
|
||||||
}
|
|
||||||
|
|
||||||
document.querySelectorAll('.rsk').forEach(function (rskElem) {
|
document.querySelectorAll('.rsk').forEach(function (rskElem) {
|
||||||
rskElem.addEventListener('click', function (e) {
|
rskElem.addEventListener('click', function (e) {
|
||||||
rsk()
|
rsk()
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
if (navigator.canShare && navigator.canShare({ url: '' })) {
|
|
||||||
document.getElementById('title').addEventListener('click', function () {
|
|
||||||
navigator.share({ url: '' });
|
|
||||||
})
|
|
||||||
}
|
|
||||||
|
|
||||||
var content = document.getElementsByClassName('content')[0]
|
var content = document.getElementsByClassName('content')[0]
|
||||||
content.focus()
|
content.focus()
|
||||||
content.addEventListener('keydown', function (e) {
|
content.addEventListener('keydown', function (e) {
|
||||||
|
|
Loading…
Add table
Reference in a new issue