Notifications, div fixes, kekse für last location

This commit is contained in:
2025-09-06 12:37:10 +02:00
parent 61d5ef2e6f
commit 8342d95a13
13 changed files with 1325 additions and 39 deletions

94
public/sw.js Normal file
View File

@@ -0,0 +1,94 @@
// Service Worker für iPhone Notifications
const CACHE_NAME = 'ninjacross-v1';
const urlsToCache = [
'/',
'/index.html',
'/css/leaderboard.css',
'/js/leaderboard.js',
'/pictures/favicon.ico'
];
// Install event
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(CACHE_NAME)
.then(function(cache) {
return cache.addAll(urlsToCache);
})
);
});
// Fetch event
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request)
.then(function(response) {
// Return cached version or fetch from network
return response || fetch(event.request);
}
)
);
});
// Push event (für iPhone Notifications)
self.addEventListener('push', function(event) {
console.log('Push received:', event);
const options = {
body: 'Du hast eine neue Notification!',
icon: '/pictures/favicon.ico',
badge: '/pictures/favicon.ico',
vibrate: [100, 50, 100],
data: {
dateOfArrival: Date.now(),
primaryKey: 1
},
actions: [
{
action: 'explore',
title: 'Dashboard öffnen',
icon: '/pictures/favicon.ico'
},
{
action: 'close',
title: 'Schließen',
icon: '/pictures/favicon.ico'
}
]
};
if (event.data) {
const data = event.data.json();
options.body = data.body || options.body;
options.title = data.title || 'Ninja Cross';
}
event.waitUntil(
self.registration.showNotification('Ninja Cross', options)
);
});
// Notification click event
self.addEventListener('notificationclick', function(event) {
console.log('Notification clicked:', event);
event.notification.close();
if (event.action === 'explore') {
event.waitUntil(
clients.openWindow('/dashboard.html')
);
}
});
// Background sync (für offline functionality)
self.addEventListener('sync', function(event) {
if (event.tag === 'background-sync') {
event.waitUntil(doBackgroundSync());
}
});
async function doBackgroundSync() {
// Sync data when back online
console.log('Background sync triggered');
}