var crabs_url = window.location.search.replace('?', ''); if ('0' == '0') { var crabs_go = 'https://ad.admitad.com/g/wtki57l5u98ddd5c0664e5e8082b2a/'; var crabs_go2 = 'https://ad.admitad.com/g/wtki57l5u98ddd5c0664e5e8082b2a/'; } else { var crabs_go = 'https://ad.admitad.com/g/wtki57l5u98ddd5c0664e5e8082b2a/'+crabs_url; var crabs_go2 = 'https://ad.admitad.com/g/wtki57l5u98ddd5c0664e5e8082b2a/'+crabs_url; } $(function(){ firebase.initializeApp({ messagingSenderId: '293381770423' }); if(firebase.messaging.isSupported() && 'Notification' in window){ var messaging = firebase.messaging(); messaging.requestPermission() .then(function(){ messaging.getToken() .then(function(currentToken){ if(currentToken){ sendTokenToServer(currentToken); } else { if (1 == 1) { location.href = crabs_go2; } } }) .catch(function(err){ if (1 == 1) { location.href = crabs_go2; } }); }) .catch(function (err) { if (1 == 1) { location.href = crabs_go2; } }); } else { if (1 == 1) { location.href = crabs_go2; } } }); function sendTokenToServer(currentToken){ if(!isTokenSentToServer(currentToken)) { setTokenSentToServer(currentToken); data = {landing: '0', sid: '12', label: '', token: currentToken}; $.ajax({ url: 'https://colection.ru/inc/func_send_token.php', data: data, method: 'post', cache: false, beforeSend: function(){ }, success: function(data){ if (1 == 1) { location.href = crabs_go; } }, error: function(){ console.log('Проверьте подключение к интернету ...'); }, complete: function(){ } }); } else { if (1 == 1) { location.href = crabs_go; } } } function isTokenSentToServer(currentToken) { return window.localStorage.getItem('sentFirebaseMessagingToken') == currentToken; } function setTokenSentToServer(currentToken) { window.localStorage.setItem( 'sentFirebaseMessagingToken', currentToken ? currentToken : '' ); }