Skip to content

Commit

Permalink
added html5 notifications functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
cankurttekin committed Sep 27, 2024
1 parent 89427f3 commit dd9a1fa
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
20 changes: 20 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ async function fetchTrips() {

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


// Request permission for notifications
document.addEventListener('DOMContentLoaded', function() {
if (Notification.permission !== "granted") {
Notification.requestPermission();
}
});

function sendNotification(title, body) {
if (Notification.permission === "granted") {
new Notification(title, {
body: body,
icon: 'tcdd-cli.png'
});
}
}

function checkTrip(trip) {
let seatType = document.getElementById('seatType').value;
let disabled_seat_count = 0;
Expand Down Expand Up @@ -162,6 +179,7 @@ function checkTrip(trip) {
&emsp;&emsp;♿ Disabled: ${disabled_seat_count}<br/>`;
found = true;
audio.play();
sendNotification('Economy seats available', `${tripDate}, ${tripTime} - Economy: ${economy_seat_count}`);
} else if (seatType === "business" && business_seat_count > 0) {
document.getElementById("status").innerHTML
+= `<br/><span style="color:Tomato;"><b>Business seats available for:</b></span><br/>
Expand All @@ -171,6 +189,8 @@ function checkTrip(trip) {
&emsp;&emsp;♿ Disabled: ${disabled_seat_count}<br/> `;
found = true;
audio.play();
sendNotification('Business seats available', `${tripDate}, ${tripTime} - Business: ${business_seat_count}`);

}
}

Expand Down
1 change: 1 addition & 0 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="style.css">
<link rel="icon" type="image/x-icon" href="tcdd-cli.png">
<title>TCDD-CLI Web</title>
</head>
<body>
Expand Down

0 comments on commit dd9a1fa

Please sign in to comment.