1 2/* 3 * 4 * Push Notifications codelab 5 * Copyright 2015 Google Inc. All rights reserved. 6 * 7 * Licensed under the Apache License, Version 2.0 (the "License"); 8 * you may not use this file except in compliance with the License. 9 * You may obtain a copy of the License at 10 * 11 * https://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, software 14 * distributed under the License is distributed on an "AS IS" BASIS, 15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 * See the License for the specific language governing permissions and 17 * limitations under the License 18 * 19 */ 20 21// Version 0.1 22 23'use strict'; 24 25self.addEventListener('install', event => { 26 self.skipWaiting(); 27}); 28 29self.addEventListener('fetch', event => { 30}); 31 32self.addEventListener('activate', event => { 33}); 34 35self.addEventListener('push', (event, k) => { 36 let str = event.data.text().split('||'); 37 console.log(str); 38 let notification = { 39 'body': str[1], 40 'icon': str[3].replace('http://','https://'), 41 'tag': str[2], 42 'requireInteraction': true 43 }; 44 45 if(typeof str[4] !== 'undefined'){ 46 notification.image = str[4].replace('http://','https://'); 47 } 48 49 event.waitUntil( 50 self.registration.showNotification(str[0],notification) 51 ); 52}); 53 54self.addEventListener('notificationclick', event => { 55 let url = event.notification.tag; 56 event.notification.close(); 57 event.waitUntil( 58 clients.matchAll({ 59 type: 'window' 60 }) 61 .then(function(windowClients) { 62 for (let i = 0; i < windowClients.length; i ) { 63 let client = windowClients[i]; 64 if (client.url === url && 'focus' in client) { 65 return client.focus(); 66 } 67 } 68 if (clients.openWindow) { 69 return clients.openWindow(url); 70 } 71 })); 72});
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.