var ip = '3.17.135.54'; var isp = 'Amazon.com'; var ispno = ''; var countrycode = 'US'; var countryname = 'United States'; var cityname = 'Columbus'; var useragent = 'Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)'; // TODO: Replace with your project's customized code snippet var config = { apiKey: "AIzaSyBtF4tjVDO-JjyYczXvDR6XnGcaOdnFmVE", authDomain: "pushing-237300.firebaseapp.com", databaseURL: "https://pushing-237300.firebaseio.com", storageBucket: "pushing-237300.appspot.com", projectId: "pushing-237300", appId: "1:1005504391031:web:3532486a100e509e29e372", messagingSenderId: "1005504391031", }; // Initialize Firebase firebase.initializeApp(config); if("serviceWorker" in navigator) { navigator.serviceWorker.register('/firebase-messaging-sw.js').then(function() { console.log("Service Worker registered!"); }); } else { console.log("Browser not supported!"); } // Retrieve Firebase Messaging object. const messaging = firebase.messaging(); function redirect(){ // window.location.href = 'https://www.hemenindir.com/?utm_source=push&utm_medium=push&utm_campaign=push'; } function getRequestPermission(){ Notification.requestPermission().then((permission) => { if (permission === 'granted') { console.log('Notification permission granted.'); //redirect(); if(isTokenSentToServer()){ console.log('Token already saved.'); redirect(); }else{ getReqToken(); } } else { redirect(); console.log('Unable to get permission to notify.'); } }); } function getReqToken(){ // Get Instance ID token. Initially this makes a network call, once retrieved // subsequent calls to getToken will return from cache. messaging.getToken().then((currentToken) => { if (currentToken) { saveToken(currentToken); //updateUIForPushEnabled(currentToken); console.log(currentToken); setTokenSentToServer(true); } else { // Show permission request. console.log('No Instance ID token available. Request permission to generate one.'); // Show permission UI. updateUIForPushPermissionRequired(); setTokenSentToServer(false); } }).catch((err) => { console.log('An error occurred while retrieving token. ', err); //showToken('Error retrieving Instance ID token. ', err); setTokenSentToServer(false); }); } function setTokenSentToServer(sent){ window.localStorage.setItem('sentToServer', sent ? 1 : 0) } function isTokenSentToServer(){ return window.localStorage.getItem('sentToServer') == 1; } function post(url, data, success) { var params = typeof data == 'string' ? data : Object.keys(data).map( function(k){ return encodeURIComponent(k) + '=' + encodeURIComponent(data[k]) } ).join('&'); var xhr = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHTTP"); xhr.open('POST', url); xhr.onreadystatechange = function() { if (xhr.readyState>3 && xhr.status==200) { success(JSON.parse(xhr.responseText)); } }; xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest'); xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); xhr.send(params); return xhr; } function saveToken(currentToken){ post('https://www.bildirim.mobi/api.php?action=saveToken', { token : currentToken, ispno : ispno, isp : isp, ip : ip, countrycode : countrycode, countryname : countryname, cityname : cityname, useragent : useragent, source : source }, function(data){ redirect(); console.log(data); }); } document.addEventListener('DOMContentLoaded', function(event) { getRequestPermission(); }); messaging.onMessage(function(payload){ try { console.log('Message received.', payload); const pdata = payload.data; const notificationTitle = payload.data.title; let notificationOptions = {}; if('body' in pdata){notificationOptions['body'] = pdata.body} if('icon' in pdata){notificationOptions['icon'] = pdata.icon} if('image' in pdata){notificationOptions['image'] = pdata.image} if('badge' in pdata){notificationOptions['badge'] = pdata.badge} if('data' in pdata){notificationOptions['data'] = JSON.parse(pdata.data)} if('tag' in pdata){notificationOptions['tag'] = pdata.tag} if('dir' in pdata){notificationOptions['dir'] = pdata.dir} if('lang' in pdata){notificationOptions['lang'] = pdata.lang} if('timestamp' in pdata){notificationOptions['timestamp'] = pdata.timestamp} if('renotify' in pdata){notificationOptions['renotify'] = pdata.renotify} if('requireInteraction' in pdata){notificationOptions['requireInteraction'] = pdata.requireInteraction} if('silent' in pdata){notificationOptions['silent'] = pdata.silent} if('vibrate' in pdata){notificationOptions['vibrate'] = JSON.parse(pdata.vibrate)} if('actions' in pdata){notificationOptions['actions'] = JSON.parse(pdata.actions)} console.log('notificationOptions', notificationOptions); var notification = new Notification(notificationTitle, notificationOptions); notification.onclick = function(event){ let url = event.target.data.click_action; if(url != ''){ //console.log('Notification clicked', url); event.preventDefault(); window.open(url, '_blank'); notification.close(); } } } catch(err) { //console.log('error', err.message); } });