-
Notifications
You must be signed in to change notification settings - Fork 0
/
home.js
31 lines (28 loc) · 1.23 KB
/
home.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
// Toggle Dark Mode
var darkModeCheckbox = document.getElementById('darkModeCheckbox');
var darkModePreference = localStorage.getItem('darkMode') === 'true';
document.body.classList.toggle('dark-mode', darkModePreference);
darkModeCheckbox.checked = darkModePreference;
darkModeCheckbox.addEventListener('change', function(event) {
document.body.classList.toggle('dark-mode', event.target.checked);
localStorage.setItem('darkMode', event.target.checked);
});
// Update Shuttle Count
function updateShuttleCount() {
fetch('/active-shuttles') // Endpoint to get active shuttles
.then(response => response.json())
.then(data => {
if (data && data.activeShuttles !== undefined) {
document.getElementById('shuttles-online').textContent = `${data.activeShuttles} active`;
} else {
document.getElementById('shuttles-online').textContent = 'No data available';
}
})
.catch(error => {
console.error('Error fetching active shuttles:', error);
document.getElementById('shuttles-online').textContent = 'Failed to fetch data';
});
}
document.addEventListener('DOMContentLoaded', function() {
updateShuttleCount();
});