/* Notification-only worker: no fetch handler or application cache. */ 'use strict'; self.addEventListener('install',event=>event.waitUntil(self.skipWaiting())); self.addEventListener('push',event=>event.waitUntil((async()=>{ let data;try{data=event.data.json();}catch{return;}if(!data||!/^[0-9a-f-]{36}$/.test(data.uuid||''))return; const clients=await self.clients.matchAll({type:'window',includeUncontrolled:true});clients.forEach(client=>client.postMessage({type:'pageswiki-notification'})); const ja=(self.navigator.language||'').startsWith('ja');await self.registration.showNotification(ja?'PagesWiki: 新着通知':'PagesWiki: new notification',{body:ja?'Inboxで確認できます。':'Open your Inbox to read it.',tag:'pageswiki-inbox',data:{url:'/v/notification?uuid='+encodeURIComponent(data.uuid)}}); })())); self.addEventListener('notificationclick',event=>{event.notification.close();event.waitUntil((async()=>{const u=new URL(event.notification.data?.url||'/v/notification',self.location.origin);if(u.origin!==self.location.origin||u.pathname!=='/v/notification')return;const clients=await self.clients.matchAll({type:'window',includeUncontrolled:true}),existing=clients.find(c=>new URL(c.url).pathname==='/v/notification');if(existing){await existing.navigate(u.href);await existing.focus();}else await self.clients.openWindow(u.href);})());});