diff --git a/items.js b/items.js index ba684b9..6909b07 100644 --- a/items.js +++ b/items.js @@ -15,17 +15,19 @@ function nav(offset) { } function handleKeyDown(e) { - switch (e.key) { - case 'ArrowUp': - e.preventDefault() - e.stopPropagation() - nav(-1) - break - case 'ArrowDown': - e.preventDefault() - e.stopPropagation() - nav(1) - break + if (e.target.classList.contains('items')) { + switch (e.key) { + case 'ArrowUp': + e.preventDefault() + e.stopPropagation() + nav(-1) + break + case 'ArrowDown': + e.preventDefault() + e.stopPropagation() + nav(1) + break + } } } diff --git a/sw.js b/sw.js index 5e919ac..fb13aa4 100644 --- a/sw.js +++ b/sw.js @@ -1,4 +1,4 @@ -const VERSION = 'v5' +const VERSION = 'v6' const API_ORIGIN = 'https://scraper.infotren.dcdev.ro/' const API_TRAINS = `${API_ORIGIN}v3/trains` const API_STATIONS = `${API_ORIGIN}v2/stations` diff --git a/view-train.css b/view-train.css index faec677..0274987 100644 --- a/view-train.css +++ b/view-train.css @@ -38,7 +38,8 @@ grid-template-areas: "arr name dep" "arr km dep" - "arr platform dep"; + "arr platform dep" + "arr notes dep"; padding: 4px 0; } @@ -87,6 +88,14 @@ grid-area: platform; } +.stationItem .notes { + grid-area: notes; +} + +.stationItem .note { + text-align: center; +} + .last-refreshed { font-size: 12px; text-transform: none; diff --git a/view-train.js b/view-train.js index cd0c7ca..12dd02a 100644 --- a/view-train.js +++ b/view-train.js @@ -257,6 +257,37 @@ function onTrainData(data) { stationPlatform.textContent = `platform ${station.platform}` stationPlatform.classList.add('thi', 'platform') } + + if (station.notes && station.notes.length > 0) { + var stationNotes = document.createElement('div') + stationItem.appendChild(stationNotes) + stationNotes.classList.add('notes') + + station.notes.forEach(function (note) { + var noteP = document.createElement('p') + stationNotes.appendChild(noteP) + noteP.classList.add('note', 'thi') + + switch (note.kind) { + case 'departsAs': { + noteP.textContent = `Train departs as ${note.rank} ${note.number}` + break + } + case 'detachingWagons': { + noteP.textContent = `Detaching wagons to ${note.station}` + break + } + case 'receivingWagons': { + noteP.textContent = `Receiving wagons from ${note.station}` + break + } + case 'trainNumberChange': { + noteP.textContent = `Train changes number to ${note.rank} ${note.number}` + break + } + } + }) + } }) lastSuccessfulFetch = new Date()