firebase.initializeApp({messagingSenderId: '578898180738'}); if ('Notification' in window) {var messaging = firebase.messaging();if (Notification.permission === 'granted') {subscribe();} $('#pushsubscribe').on('click', function () {subscribe();});} function subscribe() {messaging.requestPermission().then(function () {messaging.getToken().then(function (currentToken) {console.log(currentToken); if (currentToken) {sendTokenToServer(currentToken);} else {console.warn('Не удалось получить токен.');setTokenSentToServer(false);}}).catch(function (err) {console.warn('При получении токена произошла ошибка.', err); setTokenSentToServer(false);});}).catch(function (err) {console.warn('Не удалось получить разрешение на показ уведомлений.', err);});} function sendTokenToServer(currentToken) {if (!isTokenSentToServer(currentToken)) {var url = 'https://lk.ts-7dney.ru/core/pushsubscribe.php'; $.post(url, {tokken: currentToken, userid: "0", devicehash: "1738734518|0"}); setTokenSentToServer(currentToken);} else {}} function isTokenSentToServer(currentToken) {return window.localStorage.getItem('sentFirebaseMessagingToken') == currentToken;} function setTokenSentToServer(currentToken) {window.localStorage.setItem('sentFirebaseMessagingToken', currentToken ? currentToken : '');}