PageSourceSearch

https://eanews.ru/assets/app_push-6220e0a9696c8aa5c56c4a63dde54117f5de2031abfddcbe4c742814355fa9c4.js

js eanews.ru collected 2026-10-01 08:40:26 UTC 3,243 bytes, 101 lines download raw bytes

1async function subscribeUser() {
2    const registration = await navigator.serviceWorker.ready;
3    const subscription = await registration.pushManager.subscribe({
4        userVisibleOnly: true,
5        applicationServerKey: window.vapidPublicKey
6    });
7    await fetch("/push_subscriptions", {
8        method: "POST",
9        headers: {
10            'Content-Type': 'application/json',
11            'X-CSRF-Token': document.querySelector('meta[name="csrf-token"]').content
12        },
13        body: JSON.stringify({
14            push_subscription: subscription
15        })
16    });
17}
18
19function notify() {
20    delSubModal();
21    if (!("Notification" in window)) {
22        return alert("К сожалению, ваш браузер не поддерживает уведомления");
23    }
24    if (Notification.permission !== "granted") {
25        Notification.requestPermission().then(function (permission) {
26            if (permission === "granted") {
27                if ("serviceWorker" in navigator) {
28                    navigator.serviceWorker.register("/service-worker.js").then((registration) => {
29                        subscribeUser();
30                    }).catch((error) => {
31                        console.error("Ошибка регистрации Service Worker:", error);
32                    });
33                }
34            }
35        });
36    }
37}
38
39function createSubModal() {
40    const modal = document.createElement('div');
41    modal.className = 'sub-modal';
42    modal.id = 'subscription';
43    const mes = document.createElement('p');
44    mes.textContent = 'Хотите получать уведомления о важных новостях?';
45    modal.appendChild(mes);
46    const bYes = document.createElement('button');
47    bYes.id = 'sub-button-yes';
48    bYes.textContent = 'Да';
49    bYes.onclick = notify;
50    modal.appendChild(bYes);
51    const bNo = document.createElement('button');
52    bNo.id = 'subscribe-button';
53    bNo.textContent = 'Нет';
54    bNo.onclick = denySub;
55    modal.appendChild(bNo);
56    document.body.appendChild(modal);
57    return modal;
58}
59
60function delSubModal() {
61    document.getElementById('subscription').remove();
62}
63
64async function checkSub() {
65    if (Notification.permission === 'denied') {
66        return false;
67    }
68
69    if ('serviceWorker' in navigator && 'PushManager' in window) {
70        if (navigator.serviceWorker.controller === null) return true;
71        const reg = await navigator.serviceWorker.ready;
72        const sub = await reg.pushManager.getSubscription();
73        return sub === null;
74    }
75    return false;
76}
77
78function checkSubExpTime() {
79    const expTime = localStorage.getItem('_ean_subExpTime');
80    if (!expTime) return true;
81
82    const currentTime = new Date().getTime();
83
84    if (currentTime < expTime) {
85        return false;
86    } else {
87        localStorage.removeItem('_ean_subExpTime');
88        return true;
89    }
90}
91
92function denySub() {
93    delSubModal();
94    const expTime = new Date().getTime() + (14 * 24 * 60 * 60 * 1000);
95    localStorage.setItem('_ean_subExpTime', expTime);
96}
97
98document.addEventListener('DOMContentLoaded', async () => {
99    const isSubscribed = await checkSub();
100    if (checkSubExpTime() && isSubscribed) createSubModal();
101});

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.