1"use strict";class WebPush{constructor(){if(this.pushBell=document.querySelector(".js__webPush--bell"),this.pushOpenPopup=document.querySelector(".js__webPush--openPopup"),this.pushInfo=document.querySelector(".js__webPush--info"),this.pushMessage=document.querySelector(".js__webPush--message"),this.popupContainer=document.querySelector("#js__popupContainer"),this.delayedPopupTimer=null,this.configElement=document.getElementById("js_sw_config"),this.config=JSON.parse(this.configElement.innerText),!this.config.sw.publicKey)return debug("Could not find the Web Push public key!"),!1;this.classes={hide:"-hide",active:"-active"},this.pushBell&&this.pushOpenPopup&&this.pushInfo&&this.pushMessage&&this.popupContainer&&(this.pushIsLockReason=null,this.checkLockBell()||("granted"===Notification.permission?this.getPushSubscription().then(e=>{if(e){const s=localStorage.getItem("service_worker_notification_valid_date");if(!s||s+864e5<Date.now())return fetch("api/webpush/validate",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(function(e){if(!e.ok||200!==e.status)throw new Error(`Server responded with status code ${e.status}`);return e.json()}).then(e=>{e.valid?localStorage.setItem("service_worker_notification_valid_date",Date.now()):this.unsubscribeUser().then(()=>{this.subscribeUser()})})}else this.subscribeUser()}):(this.pushBell.classList.remove("-hide"),this.pushOpenPopup.dataset.module="webpush",this.pushOpenPopup.dataset.template="webpush_modal",addPopupButtonEvents(".js__webPush--openPopup",()=>{this.addPopupEvents(),this.delayedPopupTimer&&clearTimeout(this.delayedPopupTimer),localStorage.setItem("webpush_popup_was_displayed","1")}))))}checkPushIsSupported(){return"serviceWorker"in navigator&&"PushManager"in window}checkPushIsBlocked(){return"Notification"in window&&"denied"===Notification.permission}delayedPopup(){localStorage.getItem("webpush_popup_was_displayed")||(this.delayedPopupTimer=setTimeout(()=>{localStorage.getItem("webpush_popup_was_displayed")||loadPopup("webpush","webpush_modal").then(()=>{this.addPopupEvents(),localStorage.setItem("webpush_popup_was_displayed","1")})},5e3))}addPopupEvents(){const e=this.popupContainer.querySelector(".module");e&&e.addEventListener("click",e=>{("js__webpushEnableButton"===e.target.id||e.target.closest("#js__webpushEnableButton"))&&(popupClose(),this.askPermission().then(e=>{e?(this.pushBell.classList.add("-hide"),this.subscribeUser()):this.checkLockBell()}))})}checkLockBell(){return this.checkPushIsBlocked()?this.pushIsLockReason="blocked":this.checkPushIsSupported()||(this.pushIsLockReason="unsupported"),!!this.pushIsLockReason&&(this.pushBell.classList.remove("-hide"),this.pushInfo.classList.remove("-hide"),this.pushOpenPopup.dataset.lock=!0,this.pushInfo.innerText=this.pushInfo.dataset[this.pushIsLockReason],this.pushOpenPopup.addEventListener("click",e=>{e.preventDefault(),e.stopPropagation(),this.pushInfo.classList.toggle(this.classes.active)}),!0)}askPermission(){return new Promise(function(e,s){const t=Notification.requestPermission(function(s){e(s)});t&&t.then(e,s)}).then(function(e){return"granted"===e})}unsubscribeUser(){return navigator.serviceWorker.ready.then(e=>{e.pushManager.getSubscription().then(e=>{e.unsubscribe().then(e=>!0).catch(e=>!1)})})}subscribeUser(){navigator.serviceWorker.ready.then(e=>{const s={userVisibleOnly:!0,applicationServerKey:this.formatPublicKeyString(this.config.sw.publicKey)};return e.pushManager.subscribe(s)}).then(e=>(debug("Received PushSubscription: ",JSON.stringify(e)),this.saveSubscription(e))).then(()=>{localStorage.setItem("service_worker_notification_valid_date",Date.now()),this.pushMessage.classList.remove(this.classes.hide),this.pushMessage.classList.add(this.classes.active),this.delayedPopupTimer=setTimeout(()=>{this.pushMessage.classList.remove(this.classes.active)},2500)})}formatPublicKeyString(e){const s=(e+"=".repeat((4-e.length%4)%4)).replace(/\-/g,"+").replace(/_/g,"/"),t=window.atob(s),i=new Uint8Array(t.length);for(let e=0;e<t.length;++e)i[e]=t.charCodeAt(e);return i}saveSubscription(e){return fetch("api/webpush/subscribe",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(e)}).then(function(e){if(!e.ok||200!==e.status)throw new Error(`Server responded with status code ${e.status}`);return e.json()}).then(function(e){debug(e)})}getPushSubscription(){return window.navigator.serviceWorker.ready.then(function(e){return e.pushManager.getSubscription().then(function(e){return e}).catch(function(e){debug("Error getting push subscription",e)})})}}"loading"===document.readyState?document.addEventListener("DOMContentLoaded",function(){new WebPush}):new WebPush;
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.