1 2 self.addEventListener('install', (event) => { 3 self.skipWaiting(); 4 }); 5 6 self.addEventListener('activate', (event) => { 7 event.waitUntil(clients.claim()); 8 }); 9 10 self.addEventListener('push', (event) => { 11 let title = 'Bescot Banter'; 12 let articleUrl = 'https://www.bescotbanter.net'; 13 let bodyText = ''; 14 let iconUrl = 'https://i.postimg.cc/7LQ2DbvF/Bescot_Banter_Icon.png'; 15 let heroImageUrl = null; 16 let customActions = [{ action: 'open', title: 'Read More' }]; 17 let notificationTag = 'bescot-banter-' + Date.now(); 18 19 if (event.data) { 20 try { 21 const payload = event.data.json(); 22 if (payload) { 23 if (payload.title) title = payload.title; 24 if (payload.link) articleUrl = payload.link; 25 if (payload.body) bodyText = payload.body; 26 if (payload.icon) iconUrl = payload.icon; 27 if (payload.image) heroImageUrl = payload.image; 28 if (payload.actions && Array.isArray(payload.actions)) customActions = payload.actions; 29 if (payload.tag) notificationTag = payload.tag; 30 } 31 } catch (e) {} 32 } 33 34 if (articleUrl && articleUrl.startsWith('http://')) { 35 articleUrl = articleUrl.replace('http://', 'https://'); 36 } 37 38 const options = { 39 body: bodyText || 'New match update on Bescot Banter', 40 icon: iconUrl, 41 badge: 'https://i.postimg.cc/7LQ2DbvF/Bescot_Banter_Icon.png', 42 image: heroImageUrl, 43 data: { url: articleUrl }, 44 tag: notificationTag, 45 renotify: true, 46 requireInteraction: false, 47 actions: customActions 48 }; 49 50 event.waitUntil( 51 self.registration.showNotification(title, options) 52 ); 53 }); 54 55 self.addEventListener('notificationclick', (event) => { 56 event.notification.close(); 57 let targetUrl = event.notification.data && event.notification.data.url ? event.notification.data.url : 'https://www.bescotbanter.net'; 58 59 if (event.action === 'share') { 60 targetUrl = 'https://twitter.com/intent/tweet?text=' + encodeURIComponent(event.notification.title) + '&url=' + encodeURIComponent(targetUrl); 61 } 62 63 if (targetUrl.startsWith('http://')) { 64 targetUrl = targetUrl.replace('http://', 'https://'); 65 } 66 67 event.waitUntil( 68 clients.matchAll({ type: 'window', includeUncontrolled: true }).then((clientList) => { 69 for (const client of clientList) { 70 if (client.url.includes('bescotbanter.net') && 'focus' in client) { 71 if ('navigate' in client) { 72 client.navigate(targetUrl); 73 } 74 return client.focus(); 75 } 76 } 77 if (clients.openWindow) return clients.openWindow(targetUrl); 78 }) 79 ); 80 }); 81
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.