1var UA = ''; 2 3self.addEventListener('install', event => { 4 self.skipWaiting(); 5}); 6 7self.addEventListener("message", function(event) { 8 UA = event.data; 9}, false); 10 11self.addEventListener('push', function (event) { 12 if (!(self.Notification && self.Notification.permission === 'granted')) { 13 return; 14 } 15 16 const sendNotification = params => { 17 const notif = JSON.parse(params); 18 const title = notif.title; 19 const body = notif.body; 20 const icon = notif.icon; 21 const data = { 22 open: notif.data.open, 23 click: (UA == 'mobile' ? notif.data.click_mobile : notif.data.click_desktop) 24 }; 25 26 fetch(data.open); 27 28 return self.registration.showNotification(title, { 29 body: body, 30 icon: icon, 31 data: data 32 }); 33 }; 34 35 if (event.data) { 36 const message = event.data.text(); 37 event.waitUntil(sendNotification(message)); 38 } 39}); 40 41self.addEventListener('notificationclick', function(event) { 42 let url = event.notification.data.click; 43 if (url.indexOf('BASE_URL') > -1) { 44 url = url.replace('BASE_URL', encodeURIComponent(self.location.origin)); 45 } 46 event.notification.close(); // Android needs explicit close. 47 event.waitUntil( 48 clients.matchAll({type: 'window'}).then( windowClients => { 49 // Open the target URL in a new window/tab. 50 if (clients.openWindow) { 51 return clients.openWindow(url); 52 } 53 }) 54 ); 55});
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.