-
Notifications
You must be signed in to change notification settings - Fork 0
/
eta.html
186 lines (158 loc) · 6.11 KB
/
eta.html
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Train Schedule TV Interface</title>
<style>
body {
margin: 0;
padding: 0;
background-color: #000;
color: #fff;
font-family: Arial, sans-serif;
overflow: hidden;
}
.tv-container {
width: 100vw;
height: 100vh;
display: flex;
justify-content: center;
align-items: center;
}
.tv-screen {
width: 90%;
height: 90%;
display: flex;
justify-content: center;
align-items: center;
}
.schedule {
width: 100%;
max-width: 1600px; /* Adjust max-width as needed */
padding: 20px;
background-color: rgba(0, 0, 0, 0.5);
border: 2px solid #fff;
border-radius: 20px;
display: flex;
overflow-x: auto;
scrollbar-width: none; /* Firefox */
-ms-overflow-style: none; /* IE and Edge */
}
.platform {
flex: 0 0 auto;
margin-right: 20px;
}
.platform:last-child {
margin-right: 0;
}
.platform-heading {
font-size: 40px; /* Larger font size for TV */
margin-bottom: 10px;
}
.route-container {
display: flex;
flex-direction: column;
}
.route {
padding: 20px;
background-color: rgba(255, 255, 255, 0.1);
border-radius: 20px;
margin-bottom: 30px;
}
.route h2 {
font-size: 36px; /* Larger font size for TV */
margin-bottom: 10px;
}
.route-item {
font-size: 32px; /* Larger font size for TV */
margin-bottom: 10px;
}
.route-item span {
font-weight: bold;
}
.route-item .time {
margin-left: 10px;
}
/* Hide scrollbar */
.schedule::-webkit-scrollbar {
display: none; /* Chrome, Safari, Opera */
}
</style>
</head>
<body>
<div class="tv-container">
<div class="tv-screen">
<div class="schedule" id="scheduleData"></div>
</div>
</div>
<script>
function fetchAndUpdateData() {
fetch(`https://rt.data.gov.hk/v1/transport/mtr/lrt/getSchedule?station_id=100`)
.then(response => response.json())
.then(data => {
const scheduleData = document.getElementById('scheduleData');
scheduleData.innerHTML = ''; // Clear previous data
if (data.status === 1) {
const platforms = data.platform_list;
platforms.forEach(platform => {
const platformDiv = document.createElement('div');
platformDiv.classList.add('platform');
const platformIdHeading = document.createElement('h2');
platformIdHeading.classList.add('platform-heading');
platformIdHeading.textContent = `Platform ${platform.platform_id}`;
platformDiv.appendChild(platformIdHeading);
const routeContainer = document.createElement('div');
routeContainer.classList.add('route-container');
const routes = platform.route_list;
routes.forEach(route => {
const routeDiv = document.createElement('div');
routeDiv.classList.add('route');
const destination = route.dest_en;
const time = route.time_en;
const routeNo = route.route_no;
const heading = document.createElement('h2');
heading.textContent = `${destination}`;
routeDiv.appendChild(heading);
const routeNumber = document.createElement('div');
routeNumber.classList.add('route-item');
routeNumber.textContent = `Route Number: ${routeNo}`;
routeDiv.appendChild(routeNumber);
const trainLength = document.createElement('div');
trainLength.classList.add('route-item');
trainLength.textContent = `Train Length: ${route.train_length}`;
routeDiv.appendChild(trainLength);
const arrivalDeparture = document.createElement('div');
arrivalDeparture.classList.add('route-item');
arrivalDeparture.textContent = `Arrival/Departure: ${route.arrival_departure}`;
routeDiv.appendChild(arrivalDeparture);
const timeInfo = document.createElement('div');
timeInfo.classList.add('route-item', 'time');
timeInfo.innerHTML = `Time: <span>${time}</span>`;
routeDiv.appendChild(timeInfo);
routeContainer.appendChild(routeDiv);
});
platformDiv.appendChild(routeContainer);
scheduleData.appendChild(platformDiv);
});
} else {
scheduleData.textContent = 'Failed to fetch data.';
}
})
.catch(error => {
console.error('Error fetching data:', error);
scheduleData.textContent = 'Failed to fetch data.';
})
.finally(() => {
// Fetch data again after 4 seconds
setTimeout(fetchAndUpdateData, 4000);
});
}
function initialize() {
fetchAndUpdateData();
}
// Initialize the UI
initialize();
</script>
</body>
</html>