-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
68 lines (58 loc) · 2.65 KB
/
script.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
window.onload = function() {
fetch('trains.json')
.then(response => response.json())
.then(trains => {
const trainList = document.getElementById('train-list');
// only process the first six trains
const limitedTrains = trains.slice(0,7)
limitedTrains.forEach(train => {
const row = document.createElement('tr');
const letterCell = document.createElement('td');
letterCell.textContent = train.Letter;
row.appendChild(letterCell);
const linesEnCell = document.createElement('td');
// check the length of the LinesEn array
if (train.LinesEn.length === 1) {
// if there is only one element in the array
linesEnCell.innerHTML = train.LinesEn[0];
} else {
// if there are two elements in the array
linesEnCell.innerHTML = `<div>${train.LinesEn[0]}</div><div class="smallerText">${train.LinesEn[1]}</div>`;
}
linesEnCell.classList.add("trainMessages"); // add the class to the cell
row.appendChild(linesEnCell);
const timeCell = document.createElement('td');
timeCell.textContent = train.FormattedDepartureTimes.FormattedFolkestoneTerminalTime
timeCell.classList.add("trainTimes"); // add the class to the cell
row.appendChild(timeCell);
trainList.appendChild(row);
});
});
}
setInterval(function() {
// code to refresh the page goes here
location.reload();
}, 30000); // 60000 milliseconds = 1 minute
setInterval(showTime, 1000);
function showTime() {
let time = new Date();
let hour = time.getHours();
let min = time.getMinutes();
let sec = time.getSeconds();
am_pm = "AM";
if (hour > 12) {
hour -= 12;
am_pm = " PM";
}
if (hour == 0) {
hr = 12;
am_pm = " AM";
}
hour = hour < 10 ? "0" + hour : hour;
min = min < 10 ? "0" + min : min;
sec = sec < 10 ? "0" + sec : sec;
let currentTime = hour + ":"
+ min + ":" + sec + am_pm;
document.getElementById("clock").innerHTML = currentTime;
}
showTime();