1import { initializeApp } from 'https://www.gstatic.com/firebasejs/10.14.0/firebase-app.js' 2import { getAnalytics } from 'https://www.gstatic.com/firebasejs/10.14.0/firebase-analytics.js' 3import { getMessaging, getToken } from 'https://www.gstatic.com/firebasejs/10.14.0/firebase-messaging.js' 4 5/*$(document).on("click","#enableNotifications1",function() { 6 let promise = Notification.requestPermission(); 7});*/ 8 9function saveToken(fire_token) { 10 if (fire_token != '') { 11 $.ajax({ 12 type: "POST", 13 url: "/token_noti", 14 dataType: "json", 15 data: { "fire_token": fire_token }, 16 success: function (response) { 17 console.log('response:: ',response); 18 } 19 }); 20 } 21} 22 23window.onload = () => { 24 'use strict'; 25 26 if ('serviceWorker' in navigator) { 27 navigator.serviceWorker 28 .register("/sw.js"); 29 } 30 31 //document.getElementById("enableNotifications").click(); 32//$( "#enableNotifications" ).trigger( "click" ); 33 34var sd=navigator.userAgent.match(/iPhone|iPad|iPod/i); 35if(sd =='iPhone' || sd =='iPad' || sd =='iPod'){ 36 37 //alert(Notification.permission); 38 if(Notification.permission=='default'){ 39 if (localStorage.getItem('set_noti') !== null) { 40 $('#modal_noti1').modal('show'); 41 }else{ 42 $('#modal_noti').modal({ 43 backdrop: 'static', 44 keyboard: false 45 }); $('#modal_noti').modal('show'); 46 } 47 }else if(Notification.permission=='denied'){ 48 $('#modal_noti1').modal('show'); 49 } 50 } 51 52 53} 54/*$(document).on("click","#enableNotifications",function() { 55 //alert('aaaaaaaaaaa'); 56 let promise = Notification.requestPermission(); 57});*/ 58const notificationButton = document.getElementById("enableNotifications"); 59 60let swRegistration = null; 61const TokenElem = document.getElementById("token"); 62const ErrElem = document.getElementById("err"); 63 64// Initialize Firebase 65// TODO: Replace with your project's customized code snippet 66const config = { 67 apiKey: "AIzaSyC1pT7lAwzQqx4vmP05HJIyDXvMo5MYsUs", 68 authDomain: "moneybar.firebaseapp.com", 69 projectId: "moneybar", 70 storageBucket: "moneybar.appspot.com", 71 messagingSenderId: "851456105280", 72 appId: "1:851456105280:web:57e0a5d73b03d3f1dbf8a5", 73 measurementId: "G-XKZ1LKTNPG" 74}; 75 76const app = initializeApp(config); 77const messaging = getMessaging(app); 78 79initializeMyApp(); 80 81function initializeMyApp() { 82 83 if ("serviceWorker" in navigator && "PushManager" in window) { 84 console.log("Service Worker and Push is supported"); 85 initializeUi(); 86 initializeFCM(); 87 88 //Register the service worker 89 // navigator.serviceWorker 90 // .register("sw.js") 91 // .then(swReg => { 92 // console.log("Service Worker is registered", swReg); 93 // swRegistration = swReg; 94 // }) 95 // .catch(error => { 96 // console.error("Service Worker Error", error); 97 // }); 98 // navigator.serviceWorker.ready.then(function(registration) { 99 // console.log("A service worker is active:", registration.active); 100 101 // // At this point, you can call methods that require an active 102 // // service worker, like registration.pushManager.subscribe() 103 // }); 104 } else { 105 console.warn("Push messaging is not supported"); 106 //notificationButton.textContent = "Push Not Supported"; 107 108 } 109} 110 111 112 113function initializeUi() { 114 //let promise = Notification.requestPermission(); 115 notificationButton.addEventListener("click", () => { 116 //alert('eeeeeeeee'); 117 //displayNotification(); 118 $('#modal_noti').modal('hide'); 119 //let promise = Notification.requestPermission(); 120 121 Notification.requestPermission().then(function(permission) { if(permission=='granted'){ document.getElementById('show_loading').style.display = 'block'; initializeFCM(); }else{ localStorage.setItem("set_noti", 1); } }).catch(error => { 122 //console.log("Service Worker Error "+error); 123 124 }); 125 126 127 128 129 }); 130} 131 132function initializeFCM() { 133 var sd=navigator.userAgent.match(/iPhone|iPad|iPod/i); 134if(sd =='iPhone' || sd =='iPad' || sd =='iPod'){ 135 getToken(messaging).then((currentToken) => { 136 if (currentToken) { 137 document.getElementById("token").value = currentToken; 138 document.getElementById('show_loading').style.display = 'none'; 139 saveToken(currentToken); 140 } else { 141 // Show permission request UI 142 console.log('No registration token available. Request permission to generate one.'); 143 // ... 144 } 145 }).catch((err) => { 146 console.log('An error occurred while retrieving token. ', err); 147 // ... 148 }); 149}else { 150 Notification.requestPermission().then((permission) => { 151 if (permission === 'granted') { 152 console.log('Notification permission granted.'); 153 getToken(messaging).then((currentToken) => { 154 if (currentToken) { 155 document.getElementById("token").value = currentToken; 156 saveToken(currentToken); 157 } else { 158 // Show permission request UI 159 console.log('No registration token available. Request permission to generate one.'); 160 // ... 161 } 162 }).catch((err) => { 163 console.log('An error occurred while retrieving token. ', err); 164 // ... 165 }); 166 } 167 }); 168} 169} 170 171function displayNotification() { 172 if (window.Notification && Notification.permission === "granted") { 173 notification(); 174 } 175 // If the user hasn't told if he wants to be notified or not 176 // Note: because of Chrome, we are not sure the permission property 177 // is set, therefore it's unsafe to check for the "default" value. 178 else if (window.Notification && Notification.permission !== "denied") { 179 Notification.requestPermission(status => { 180 if (status === "granted") { 181 notification(); 182 } else { 183 alert("You denied or dismissed permissions to notifications."); 184 } 185 }); 186 } else { 187 // If the user refuses to get notified 188 alert( 189 "You denied permissions to notifications. Please go to your browser or phone setting to allow notifications." 190 ); 191 } 192} 193 194function notification() { 195 const options = { 196 body: "Testing Our Notification", 197 icon: "https://moneybar.in/assets/frontend/image/bell.png" 198 }; 199 swRegistration.showNotification("PWA Notification!", options); 200} 201 202// self.addEventListener('notificationclick', function(event) { 203// console.log(event); 204// // Prevent the default notification click handler 205// event.stopImmediatePropagation(); 206 207// // Close the notification 208// event.notification.close(); 209 210// // Get the URL from the notification data (customize for your own data) 211// var url = event.notification.click_action; 212 213// // This should give focus to the PWA if it's open and navigate to the URL 214// event.waitUntil( 215// clients.matchAll({type: 'window'}).then(windowClients => { 216// for (var i = 0; i < windowClients.length; i++) { 217// var client = windowClients[i];
218// if (client.url === url && 'focus' in client) { 219// return client.focus(); 220// } 221// } 222 223// // If the PWA isn't currently open, open a new window/tab with the URL 224// if (clients.openWindow) { 225// return clients.openWindow(url); 226// } 227// }) 228// ); 229// });
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.