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.