1/* eslint-disable */ 2importScripts("https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"); 3importScripts( 4 "https://www.gstatic.com/firebasejs/8.10.0/firebase-messaging.js", 5); 6 7const firebaseConfig = { 8 apiKey: "<%= process.env.FCM_API_KEY %>", 9 authDomain: "<%= process.env.FCM_AUTH_DOMAIN %>", 10 databaseURL: "<%= process.env.FCM_DATA_BASE_URL %>", 11 projectId: "<%= process.env.FCM_PROJECT_ID %>", 12 storageBucket: "<%= process.env.FCM_STORAGE_BUCKET %>", 13 messagingSenderId: "<%= process.env.FCM_MESSAGING_SENDER_ID %>", 14 appId: "<%= process.env.FCM_APP_ID %>", 15 measurementId: "<%= process.env.FCM_MEASUREMENT_ID %>", 16}; 17 18const params = new URL(self.location); 19const device = params.searchParams.get("device"); 20 21const getClientList = () => 22 self.clients.claim().then(() => 23 self.clients.matchAll({ 24 includeUncontrolled: true, 25 type: 'window', 26 }), 27 ); 28 29// Device ID sent by client 30let firstPlatform = null; 31 32// Listen to messages from client 33self.addEventListener('message', (event) => { 34 if (event.data && event.data.idPlatform) { 35 firstPlatform = event.data.idPlatform; 36 } 37}); 38 39if (firebase.apps.length === 0) { 40 41 firebase.initializeApp(firebaseConfig); 42 43} 44 45if (firebase.messaging.isSupported()) { 46 47 const messaging = firebase.messaging(); 48 messaging.onBackgroundMessage((payload) => { 49 if (device === 'true' || device === true) return null; 50 const { message, deeplink, type } = payload.data || {}; 51 52 if (firstPlatform !== 'fds') return null; 53 54 const notificationTitle = 'Female Daily'; 55 const hasQuestionMark = /\?/.test(deeplink); 56 const notificationOptions = { 57 body: message, 58 icon: 'https://s3.ap-southeast-1.amazonaws.com/assets.femaledaily.com/web-assets/logo/fdn_logo_192.png', 59 data: { 60 url: `${deeplink}${hasQuestionMark ? `&` : `?` 61 }utm_source=web&utm_medium=web_push&utm_campaign=${type}`, 62 }, 63 requireInteraction: true, 64 silent: false, 65 }; 66 67 return self.registration.showNotification( 68 notificationTitle, 69 notificationOptions, 70 ); 71 }); 72 73 self.addEventListener( 74 "notificationclick", 75 async (event) => { 76 77 event.notification.close(); 78 event.waitUntil( 79 getClientList().then((clientList) => { 80 81 for (const client of clientList) { 82 83 if (client.url === event.notification.data.url) { 84 85 return client.focus(); 86 87 } 88 89 } 90 if (clients.openWindow) { 91 92 return clients.openWindow(event.notification.data.url); 93 94 } 95 96 }), 97 ); 98 99 }, 100 false, 101 ); 102 103}
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.