1// Import and configure the Firebase SDK 2// These scripts are made available when the app is served or deployed on Firebase Hosting 3// If you do not serve/host your project using Firebase Hosting see https://firebase.google.com/docs/web/setup 4importScripts('https://www.gstatic.com/firebasejs/8.4.1/firebase-app.js'); 5importScripts('https://www.gstatic.com/firebasejs/8.4.1/firebase-messaging.js'); 6 7const firebaseConfig = { 8 apiKey: "AIzaSyAtxVtJ_lZ0OgiDTfzfZYqwR8VJyneJfds", 9 authDomain: "seller-sprite.firebaseapp.com", 10 databaseURL: "https://seller-sprite.firebaseio.com", 11 projectId: "seller-sprite", 12 storageBucket: "seller-sprite.appspot.com", 13 messagingSenderId: "284356059972", 14 appId: "1:284356059972:web:b4c0649dfc39ef33036d11", 15 measurementId: "G-CN0F80S6GL" 16}; 17// Initialize Firebase 18firebase.initializeApp(firebaseConfig); 19 20const messaging = firebase.messaging(); 21 22/** 23 * Here is is the code snippet to initialize Firebase Messaging in the Service 24 * Worker when your app is not hosted on Firebase Hosting. 25 26 // [START initialize_firebase_in_sw] 27 // Give the service worker access to Firebase Messaging. 28 // Note that you can only use Firebase Messaging here, other Firebase libraries 29 // are not available in the service worker. 30 importScripts('https://www.gstatic.com/firebasejs/7.15.0/firebase-app.js'); 31 importScripts('https://www.gstatic.com/firebasejs/7.15.0/firebase-messaging.js'); 32 33 // Initialize the Firebase app in the service worker by passing in 34 // your app's Firebase config object. 35 // https://firebase.google.com/docs/web/setup#config-object 36 firebase.initializeApp({ 37 apiKey: 'api-key', 38 authDomain: 'project-id.firebaseapp.com', 39 databaseURL: 'https://project-id.firebaseio.com', 40 projectId: 'project-id', 41 storageBucket: 'project-id.appspot.com', 42 messagingSenderId: 'sender-id', 43 appId: 'app-id', 44 measurementId: 'G-measurement-id', 45 }); 46 47 // Retrieve an instance of Firebase Messaging so that it can handle background 48 // messages. 49const messaging = firebase.messaging(); 50 // [END initialize_firebase_in_sw] 51 **/ 52 53 54// If you would like to customize notifications that are received in the 55// background (Web app is closed or not in browser focus) then you should 56// implement this optional method. 57// [START background_handler] 58// messaging.setBackgroundMessageHandler(function (payload) { 59// console.log('[firebase-messaging-sw.js] Received background message ', payload); 60// // Customize notification here 61// const notificationTitle = 'Background Message Title'; 62// const notificationOptions = { 63// body: 'Background Message body.', 64// icon: '/assets/img/sellersprite-log.png' 65// }; 66// 67// return self.registration.showNotification(notificationTitle, notificationOptions); 68// }); 69// [END background_handler] 70messaging.onBackgroundMessage(function (payload) { 71 console.log('[firebase-messaging-sw.js] æ¶å°åå°æ¶æ¯ï¼ ', payload); 72 // Customize notification here 73 const title = (payload['notification'] && payload['notification']['title'] 74 || payload['data'] && payload['data']['title'] || 'æ¨ææ°çæ¶æ¯') + '*'; 75 let link = payload['data'] && payload['data']['callback_link'] || 'https://www.sellersprite.com/?source=firebase_sw'; 76 let id = payload['data'] && payload['data']['id'] || ''; 77 let sender = self.registration; 78 79 function _send() { 80 const options = { 81 body: payload['notification'] && payload['notification']['body'] || '(æ¥èªåå®¶ç²¾çµ) ...', 82 icon: '/assets/img/sellersprite-log.png', 83 data: {link: link} 84 }; 85 sender.showNotification(title, options); 86 } 87 88 // 鲿¢æ¶æ¯è¢«éå¤å¤ç 89 if (id !== '') { 90 // https://github.com/firebase/quickstart-js/issues/111 91 // Local Storage isn't available in service worker - you'll need to use IndexedDB which will work in both the window and the service worker. 92 // åºæ¬ä¸è¿éæ¯æ¿ä¸å° ls ç 93 let ls = self.window && self.window.localStorage || self.localStorage; 94 if (ls && ls.getItem(id)) return false;
95 let millis = Math.ceil(Math.random() * 1000); 96 let v = new Date().getTime() + '-' + millis; 97 setTimeout(function () { 98 if (ls && ls.getItem(id)) return false; 99 ls && ls.setItem(id, v); 100 if (ls && ls.getItem(id) !== v) return false; 101 _send(); 102 }, millis); 103 return true; 104 } 105 106 _send(); 107}); 108 109self.addEventListener('notificationclick', function (event) { 110 console.log('--- firebase-messaging-sw ---'); 111 console.log(event); 112 let data = event.notification.data; 113 event.notification.close(); 114 const l = data && data['link'] || 'https://www.sellersprite.com/?source=firebase_sw'; 115 const chain = self.clients.openWindow(l); 116 event.waitUntil(chain); 117});
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.