PageSourceSearch

https://www.oreanda-news.com/app/web/push.js

js oreanda-news.com collected 2026-10-02 09:56:14 UTC 12,980 bytes, 323 lines download raw bytes

1function NotificationsManager()
2{
3    var manager = this;
4    var closeWindow = false;
5    var initialized = false;
6    var isReadyToSubscribe = SITE_CONSTANTS['push_ready'];
7    var sdkUrl = 'https://cdn.onesignal.com/sdks/OneSignalSDK.js';
8    var sdkScript = null;
9    var subsTimeout = null;
10
11    this.loadSdk = function() {
12        if (sdkScript === null) {
13            sdkScript = document.createElement("script");
14            sdkScript.type = "text/javascript";
15            sdkScript.src = sdkUrl;
16            sdkScript.async = true;
17            (document.body || document.head).appendChild(sdkScript);
18        }
19    };
20
21    this.start = function() {
22        if (this.isSubscribed() && window.location.protocol === 'https:') {
23            manager.setNoticeStatus(-1, true);
24            this.subscribe();
25        } else if (!this.isNoticeDisabled() && isReadyToSubscribe) {
26            manager.setNoticeStatus(1);
27            $(document).ready(function() {
28                if (false && !manager.getCookie('onesignal-notification-prompt') && !manager.detectMobileAndTablet()) {
29                    manager.subscribe();
30                }
31                if (true) {
32                    subsTimeout = setTimeout(function() {
33                        if (!manager.isSubscribed()) {
34                            manager.subscribeIfReady();
35                        }
36                    }, 9000);
37                }
38            });
39        } else {
40            manager.setNoticeStatus(-1, true);
41        }
42        $(document).ready(function() {
43            $('.push-subscribe-notice-accept').bind('click', function() {
44                manager.subscribe(true);
45            });
46            $('.push-subscribe-notice-disable').bind('click', function() {
47                manager.setNoticeStatus(-2);
48            });
49        });
50    };
51
52    this.subscribeIfReady = function() {
53        if (isReadyToSubscribe && Notification.permission !== "denied") {
54            manager.subscribe();
55            return true;
56        }
57        return false;
58    };
59
60    this.isNoticeDisabled = function() {
61        if (this.getNoticeStatus() < -1) {
62            return true;
63        }
64        if (this.isSubscribed()) {
65            return true;
66        }
67        return false;
68    };
69
70    this.isSubscribed = function(ignorePermissions) {
71        if (window.location.protocol !== 'https:' || ignorePermissions) {
72            return this.isServiceActive() && this.isTokenExists();
73        } else {
74            return Notification.permission === 'granted' && this.isTokenExists();
75        }
76    };
77
78    this.isTokenExists = function() {
79        return this.getCookie('push_token') !== null;
80    };
81
82    this.isServiceActive = function() {
83        var v = this.getCookie('push_active');
84        return v && v !== '0';
85    };
86
87    this.setNoticeStatus = function(x, ifNotDisabled) {
88        var c = this.getNoticeStatus();
89        if (ifNotDisabled && c < 0) {
90            x = c;
91        }
92        if (x > 1) {
93            $('.push-subscribe-notice').slideDown(1000);
94        } else if (x < 0) {
95            $('.push-subscribe-notice').hide();
96        }
97        if (!x) {
98            this.deleteCookie('push_notice');
99            return true;
100        }
101        if (x === c) {
102            return false;
103        }
104        var url = '/user/notifications/';
105        $.post(url, {notice: x}, function(data) {
106            if (data == 'OK') {
107                debug.log('Set push subscribe notice status to ' + x + '...');
108            }
109        }, 'text');
110        return true;
111    };
112
113    this.getNoticeStatus = function() {
114        var v = this.getCookie('push_notice');
115        return v ? (parseInt(v, 10) || 0) : 0;
116    };
117
118    this.subscribe = function(force) {
119        this.loadSdk();
120        if (subsTimeout) {
121            clearTimeout(subsTimeout);
122        }
123        if (force) {
124            manager.setNoticeStatus(-1);
125        }
126        if (window.location.protocol !== 'https:') {
127            var secUrl = 'https://' + location.hostname + '/user/notifications/subscribe/';
128            this.openWindow(secUrl, SITE_CONSTANTS['push_subscribe_header'], 640, 320);
129            return false;
130        }
131
132        if (!initialized) {
133            initialized = true;
134            var initParams = {
135                appId: SITE_CONSTANTS['push_app_id'],
136                autoRegister: false,
137                persistNotification: false,
138                notifyButton: {
139                    enable: false
140                },
141                welcomeNotification: {
142                    title: SITE_CONSTANTS['push_subscribe_done'],
143                    message: SITE_CONSTANTS['push_subscribe_done_text']
144                },
145                promptOptions: {
146                    actionMessage: SITE_CONSTANTS['push_subscribe_text'],
147                    acceptButtonText: SITE_CONSTANTS['push_subscribe_yes'],
148                    cancelButtonText: SITE_CONSTANTS['push_subscribe_no'],
149                }
150            };
151            OneSignal.push(["init", initParams]);
152        }
153
154        OneSignal.push(function() {
155            OneSignal.isPushNotificationsEnabled(function(isEnabled) {
156                var granted = Notification.permission === 'granted';
157                var check = manager.isSubscribed(true);
158                if (check && !isEnabled || !check && isEnabled) {
159                    debug.log("The user's subscription state is now:", isEnabled);
160                    manager.update(isEnabled);
161                } else if (granted && !isEnabled && !check) {
162                    debug.log("Trying to resubscribe current user...");
163                    OneSignal.push(["setSubscription", true]);
164                    OneSignal.registerForPushNotifications();
165                }
166            });
167        });
168
169        OneSignal.push(function() {
170            OneSignal.on('subscriptionChange', function(isSubscribed) {
171                debug.log("The user's subscription state is now:", isSubscribed);
172                manager.update(isSubscribed);
173            });
174        });
175
176        if (!this.isSubscribed()) {
177            if (force) {
178                if (Notification.permission === "denied") {
179                    debug.log("Notifications are denied...");
180                    manager.sendUnsubscribe();
181                    if (SITE_CONSTANTS['push_subscribe_denied_text']) {
182                        alert(SITE_CONSTANTS['push_subscribe_denied_text']);
183                    }
184                } else {
185                    OneSignal.push(function() {
186                        debug.log("Showing native prompt...");
187                        OneSignal.showNativePrompt();
188                    });
189                }
190            } else {
191                debug.log("Showing popup prompt...");
192                manager.showPopupPrompt(force);
193            }
194        }
195
196        return false;
197    };
198
199    this.showPopupPrompt = function(force) {
200        this.deleteCookie('onesignal-notification-prompt');
201        if (force) {
202            OneSignal.push(function() {
203                OneSignal.showSlidedownPrompt({force: true});
204            });
205        } else {
206            OneSignal.push(function() {
207                OneSignal.showSlidedownPrompt();
208            });
209        }
210    };
211
212    this.subscribeWindow = function() {
213        this.loadSdk();
214        this.subscribe(true);
215        closeWindow = true;
216    };
217
218    this.openWindow = function(url, title, w, h) {
219        var dualScreenLeft = window.screenLeft !== undefined ? window.screenLeft : screen.left;
220        var dualScreenTop = window.screenTop !== undefined ? window.screenTop : screen.top;
221
222        var width = window.innerWidth ? window.innerWidth : document.documentElement.clientWidth ? document.documentElement.clientWidth : screen.width;
223        var height = window.innerHeight ? window.innerHeight : document.documentElement.clientHeight ? document.documentElement.clientHeight : screen.height;
224
225        var left = ((width / 2) - (w / 2)) + dualScreenLeft;
226        var top = ((height / 2) - (h / 2)) + dualScreenTop;
227        var newWindow = window.open(url, title, 'scrollbars=no, width=' + w + ', height=' + h + ', top=' + top + ', left=' + left);
228
229        if (window.focus) {
230            newWindow.focus();
231        }
232        return newWindow;
233    };
234
235    this.update = function(isSubscribed) {
236        debug.log('Push state update...');
237        if (isSubscribed) {
238            OneSignal.getUserId(function(userId) {
239                debug.log("OneSignal User ID:", userId);
240                manager.sendToken(userId);
241            });
242        } else {
243            manager.sendUnsubscribe();
244        }
245    };
246
247    this.sendToken = function(token) {
248        if (!this.isTokenSent(token) || !this.isServiceActive()) {
249            var url = '/user/notifications/';
250            debug.log('Sending push token to server...');
251            $.post(url, {token: ('' + token)}, function(data) {
252                if (data == 'OK') {
253                    debug.log('Done sending push token to server.');
254                }
255                if (closeWindow) {
256                    window.close();
257                }
258            }, 'text');
259        } else {
260            debug.log('Push token is already sent...');
261        }
262    };
263
264    this.sendUnsubscribe = function() {
265        if (this.isServiceActive()) {
266            var url = '/user/notifications/';
267            debug.log('Deleting push token from server...');
268            $.post(url, {'delete': 'true'}, function(data) {
269                if (data == 'OK') {
270                    debug.log('Done deleting push token from server.');
271                }
272                if (closeWindow) {
273                    window.close();
274                }
275            }, 'text');
276        } else {
277            debug.log('Push token is already deleted...');
278        }
279    };
280
281    this.isTokenSent = function(token) {
282        var value = this.getCookie('push_token');
283        if (token) {
284            return value == token;
285        } else {
286            return !value;
287        }
288    };
289
290    this.getCookie = function(name) {
291        var value = "; " + document.cookie;
292        var parts = value.split("; " + name + "=");
293        if (parts.length >= 2) {
294            return parts.pop().split(";").shift();
295        } else {
296            return null;
297        }
298    };
299
300    this.deleteCookie = function(name) {
301        document.cookie = name + '=; Path=/; Expires=Thu, 01 Jan 1970 00:00:01 GMT;';
302    };
303
304    this.detectMobileAndTablet = function() {
305        var check = false;
306        (function(a) {
307            if (/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elaine|fennec|hiptop|iemobile|ip(hone|od)|iris|kindle|lge |maemo|midp|mmp|mobile.+firefox|netfront|opera m(ob|in)i|palm( os)?|phone|p(ixi|re)\/|plucker|pocket|psp|series(4|6)0|symbian|treo|up\.(browser|link)|vodafone|wap|windows ce|xda|xiino|android|ipad|playbook|silk/i.test(a) || /1207|6310|6590|3gso|4thp|50[1-6]i|770s|802s|a wa|abac|ac(er|oo|s\-)|ai(ko|rn)|al(av|ca|co)|amoi|an(ex|ny|yw)|aptu|ar(ch|go)|as(te|us)|attw|au(di|\-m|r |s )|avan|be(ck|ll|nq)|bi(lb|rd)|bl(ac|az)|br(e|v)w|bumb|bw\-(n|u)|c55\/|capi|ccwa|cdm\-|cell|chtm|cldc|cmd\-|co(mp|nd)|craw|da(it|ll|ng)|dbte|dc\-s|devi|dica|dmob|do(c|p)o|ds(12|\-d)|el(49|ai)|em(l2|ul)|er(ic|k0)|esl8|ez([4-7]0|os|wa|ze)|fetc|fly(\-|_)|g1 u|g560|gene|gf\-5|g\-mo|go(\.w|od)|gr(ad|un)|haie|hcit|hd\-(m|p|t)|hei\-|hi(pt|ta)|hp( i|ip)|hs\-c|ht(c(\-| |_|a|g|p|s|t)|tp)|hu(aw|tc)|i\-(20|go|ma)|i230|iac( |\-|\/)|ibro|idea|ig01|ikom|im1k|inno|ipaq|iris|ja(t|v)a|jbro|jemu|jigs|kddi|keji|kgt( |\/)|klon|kpt |kwc\-|kyo(c|k)|le(no|xi)|lg( g|\/(k|l|u)|50|54|\-[a-w])|libw|lynx|m1\-w|m3ga|m50\/|ma(te|ui|xo)|mc(01|21|ca)|m\-cr|me(rc|ri)|mi(o8|oa|ts)|mmef|mo(01|02|bi|de|do|t(\-| |o|v)|zz)|mt(50|p1|v )|mwbp|mywa|n10[0-2]|n20[2-3]|n30(0|2)|n50(0|2|5)|n7(0(0|1)|10)|ne((c|m)\-|on|tf|wf|wg|wt)|nok(6|i)|nzph|o2im|op(ti|wv)|oran|owg1|p800|pan(a|d|t)|pdxg|pg(13|\-([1-8]|c))|phil|pire|pl(ay|uc)|pn\-2|po(ck|rt|se)|prox|psio|pt\-g|qa\-a|qc(07|12|21|32|60|\-[2-7]|i\-)|qtek|r380|r600|raks|rim9|ro(ve|zo)|s55\/|sa(ge|ma|mm|ms|ny|va)|sc(01|h\-|oo|p\-)|sdk\/|se(c(\-|0|1)|47|mc|nd|ri)|sgh\-|shar|sie(\-|m)|sk\-0|sl(45|id)|sm(al|ar|b3|it|t5)|so(ft|ny)|sp(01|h\-|v\-|v )|sy(01|mb)|t2(18|50)|t6(00|10|18)|ta(gt|lk)|tcl\-|tdg\-|tel(i|m)|tim\-|t\-mo|to(pl|sh)|ts(70|m\-|m3|m5)|tx\-9|up(\.b|g1|si)|utst|v400|v750|veri|vi(rg|te)|vk(40|5[0-3]|\-v)|vm40|voda|vulc|vx(52|53|60|61|70|80|81|83|85|98)|w3c(\-| )|webc|whit|wi(g |nc|nw)|wmlb|wonu|x700|yas\-|your|zeto|zte\-/i.test(a.substr(0, 4)))
308                check = true;
309        })(navigator.userAgent || navigator.vendor || window.opera);
310        return check;
311    };
312}
313
314if ('Notification' in window) {
315    window.OneSignal = window.OneSignal || [];
316    window.notificationsManager = new NotificationsManager();
317    if (Notification.permission !== "denied") {
318        window.notificationsManager.loadSdk();
319    }
320    $(document).ready(function() {
321        window.notificationsManager.start();
322    });
323}

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.