// 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/icon-192.png', badge: '/pictures/icon-192.png', vibrate: [100, 50, 100], data: { dateOfArrival: Date.now(), primaryKey: 1 }, actions: [ { action: 'explore', title: 'Dashboard öffnen', icon: '/pictures/icon-192.png' }, { action: 'close', title: 'Schließen', icon: '/pictures/icon-192.png' } ] }; 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'); }