PageSourceSearch

https://newsmaxbalkans.com/firebase.js

js newsmaxbalkans.com collected 2026-10-02 18:48:08 UTC 6,495 bytes, 187 lines download raw bytes

1// Your web app's Firebase configuration
2//window.localStorage.setItem('sentToServer', '0');
3// Your web app's Firebase configuration
4const firebaseConfig = {
5    apiKey: "AIzaSyCmb_01mlroDPd0yBT6BSaiqsU3JmKLszg",
6    authDomain: "newsmax-app.firebaseapp.com",
7    projectId: "newsmax-app",
8    storageBucket: "newsmax-app.appspot.com",
9    messagingSenderId: "800203602581",
10    appId: "1:800203602581:web:5b5ed87e126d427923f99c",
11    measurementId: "G-Z7QNK4WRLS"
12};
13
14// Initialize Firebase
15firebase.initializeApp(firebaseConfig);
16  // Initialize Analytics
17// firebase.analytics();
18
19
20// [START get_messaging_object]
21// Retrieve Firebase Messaging object.
22const messaging = firebase.messaging();
23// [END get_messaging_object]
24// [START set_public_vapid_key]
25// Add the public key generated from the console here.
26messaging.usePublicVapidKey('BDwLoSVhnRgreAvThq7ENG7tbPsyyvHZVHDGCkSurotUZ1v1Kh-EIq1dkuIgm8BYLbu3n82qzIYLo3PWYxX31_E');
27// [END set_public_vapid_key]
28
29
30//if ('serviceWorker' in navigator) {
31//    navigator.serviceWorker.register('/firebase-messaging-sw.js')
32//    .then(function (registration) {
33//        //messaging.useServiceWorker(registration);
34//        //registration.update();
35//        // registration worked
36//        console.log('Registration succeeded.');
37//    }).catch(function (error) {
38//        // registration failed
39//        console.log('Registration failed with ' + error);
40//    });
41//};
42
43// [START refresh_token]
44// Callback fired if Instance ID token is updated.
45messaging.onTokenRefresh(() => {
46    messaging.getToken().then((refreshedToken) => {
47        // console.log('Token refreshed.');
48        // Indicate that the new Instance ID token has not yet been sent to the
49        // app server.
50        setTokenSentToServer(false);
51        // Send Instance ID token to app server.
52        sendTokenToServer(refreshedToken);
53        // [START_EXCLUDE]
54        // Display new Instance ID token and clear UI of all previous messages.
55        resetUI();
56    }).catch((err) => {
57        // console.log('Unable to retrieve refreshed token ', err);
58    });
59});
60// [END refresh_token]
61
62// [START receive_message]
63// Handle incoming messages. Called when:
64// - a message is received while the app has focus
65// - the user clicks on an app notification created by a service worker
66//   `messaging.setBackgroundMessageHandler` handler.
67messaging.onMessage((payload) => {
68    // console.log('Message received. ', payload);
69});
70// [END receive_message]
71
72function resetUI() {
73    // [START get_token]
74    // Get Instance ID token. Initially this makes a network call, once retrieved
75    // subsequent calls to getToken will return from cache.
76    messaging.getToken().then((currentToken) => {
77        if (currentToken) {
78            // ok
79            sendTokenToServer(currentToken);
80        } else {
81            // Show permission request.
82            // console.log('No Instance ID token available. Request permission to generate one.');
83            // Show permission UI.
84            setTokenSentToServer(false);
85        }
86    }).catch((err) => {
87        //console.log('An error occurred while retrieving token. ', err);
88        setTokenSentToServer(false);
89    });
90    // [END get_token]
91}
92
93
94// ok
95// Send the Instance ID token your application server, so that it can:
96// - send messages back to this app
97// - subscribe/unsubscribe the token from topics
98function sendTokenToServer(currentToken) {
99    if (!isTokenSentToServer()) {
100        // console.log('Sending token to server...');
101        // TODO(developer): Send the current token to your server.
102        // ok
103        setTokenSentToServer(true);
104
105        var oldToken = 0;
106        if (window.localStorage.getItem("activeToken") !== currentToken) {
107            oldToken = window.localStorage.getItem('activeToken');
108        }
109        
110        $.ajax({
111            type: 'POST',
112            url: '/ajax/web-push-token',
113            data: {
114                newtoken : currentToken,
115                oldtoken: oldToken
116            }
117        }); 
118        
119        window.localStorage.setItem('activeToken', currentToken);
120
121    } else {
122        // console.log('Token already sent to server so won\'t send it again ' + 'unless it changes');
123    }
124
125}
126// OK
127function isTokenSentToServer() {
128    return window.localStorage.getItem('sentToServer') === '1';
129}
130// OK
131function setTokenSentToServer(sent) {
132    window.localStorage.setItem('sentToServer', sent ? '1' : '0');
133}
134
135function requestPermission() {
136    console.log('Requesting permission...');
137    // [START request_permission]
138    Notification.requestPermission().then((permission) => {
139        if (permission === 'granted') {
140            console.log('Notification permission granted.');
141            // TODO(developer): Retrieve an Instance ID token for use with FCM.
142            // [START_EXCLUDE]
143            // In many cases once an app has been granted notification permission,
144            // it should update its UI reflecting this.
145            resetUI();
146            // [END_EXCLUDE]
147        } else {
148            console.log('Unable to get permission to notify.');
149        }
150    });
151    // [END request_permission]
152}
153
154resetUI();
155
156var updateInterval = 24 * 60 * 60 * 1000;
157var currentTimestamp = new Date().getTime();
158var lastUpdatedTimestamp = localStorage.getItem('firebase_timestamp') || 0;
159if ((currentTimestamp - lastUpdatedTimestamp) > updateInterval) {
160    // send token every day
161    setTokenSentToServer(false);
162    resetUI();
163    if ('serviceWorker' in navigator) {
164        navigator.serviceWorker.register('/firebase-messaging-sw.js')
165            .then(function() {
166                localStorage.setItem('firebase_timestamp', currentTimestamp);
167                // console.log('Service worker registered!');
168            }, 
169            function() {
170                // console.log('err - Service Worker Registration Failed !')
171            });
172
173            navigator.serviceWorker.getRegistrations().then(function (registrations) {
174                for (let registration of registrations) {
175                    if (registration.active && registration.active.scriptURL != 'https://newsmaxbalkans.com/firebase-messaging-sw.js') {
176                        registration.unregister();
177                    }
178    
179                    if (registration.active && registration.active.scriptURL == 'https://newsmaxbalkans.com/firebase-messaging-sw.js') {
180                        registration.update();
181                    }
182                }
183            });
184    }
185}
186
187  

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.