Skip to content

Commit dd9a1fa

Browse files
committed
added html5 notifications functionality
1 parent 89427f3 commit dd9a1fa

File tree

2 files changed

+21
-0
lines changed

2 files changed

+21
-0
lines changed

app.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,23 @@ async function fetchTrips() {
133133

134134
var logInner = document.getElementById("log").innerHTML
135135

136+
137+
// Request permission for notifications
138+
document.addEventListener('DOMContentLoaded', function() {
139+
if (Notification.permission !== "granted") {
140+
Notification.requestPermission();
141+
}
142+
});
143+
144+
function sendNotification(title, body) {
145+
if (Notification.permission === "granted") {
146+
new Notification(title, {
147+
body: body,
148+
icon: 'tcdd-cli.png'
149+
});
150+
}
151+
}
152+
136153
function checkTrip(trip) {
137154
let seatType = document.getElementById('seatType').value;
138155
let disabled_seat_count = 0;
@@ -162,6 +179,7 @@ function checkTrip(trip) {
162179
&emsp;&emsp;♿ Disabled: ${disabled_seat_count}<br/>`;
163180
found = true;
164181
audio.play();
182+
sendNotification('Economy seats available', `${tripDate}, ${tripTime} - Economy: ${economy_seat_count}`);
165183
} else if (seatType === "business" && business_seat_count > 0) {
166184
document.getElementById("status").innerHTML
167185
+= `<br/><span style="color:Tomato;"><b>Business seats available for:</b></span><br/>
@@ -171,6 +189,8 @@ function checkTrip(trip) {
171189
&emsp;&emsp;♿ Disabled: ${disabled_seat_count}<br/> `;
172190
found = true;
173191
audio.play();
192+
sendNotification('Business seats available', `${tripDate}, ${tripTime} - Business: ${business_seat_count}`);
193+
174194
}
175195
}
176196

index.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<meta charset="UTF-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1.0">
66
<link rel="stylesheet" href="style.css">
7+
<link rel="icon" type="image/x-icon" href="tcdd-cli.png">
78
<title>TCDD-CLI Web</title>
89
</head>
910
<body>

0 commit comments

Comments
 (0)