PageSourceSearch

https://heroesworld.ru/dist/js/push-CZfJKIEd.js

js heroesworld.ru collected 2026-09-25 14:05:42 UTC 5,475 bytes, 1 lines download raw bytes

1const b="/sw.js";function o(){return typeof navigator<"u"&&"serviceWorker"in navigator&&typeof window<"u"&&"PushManager"in window&&"Notification"in window}function l(){return o()?Notification.permission:"denied"}function f(){const i=(document.documentElement.lang||"en").trim();return i.length>16?i.slice(0,16):i}async function y(){if(!o())return{supported:!1,enabled:!1,publicKey:null};try{const i=await fetch("/api/push/public-key",{credentials:"same-origin"});if(!i.ok)return{supported:!0,enabled:!1,publicKey:null};const t=await i.json();return{supported:!0,enabled:!!t.enabled,publicKey:t.publicKey??null}}catch{return{supported:!0,enabled:!1,publicKey:null}}}async function p(){const i=await navigator.serviceWorker.getRegistration();return i||navigator.serviceWorker.register(b,{scope:"/"})}async function d(){if(!o())return null;const i=await navigator.serviceWorker.getRegistration();return i?i.pushManager.getSubscription():null}function g(){return typeof navigator<"u"&&"brave"in navigator}async function w(i){if(await Notification.requestPermission()!=="granted")return"not-granted";const e=await p();await navigator.serviceWorker.ready;let s=await e.pushManager.getSubscription();if(!s)try{s=await e.pushManager.subscribe({userVisibleOnly:!0,applicationServerKey:O(i)})}catch(u){const c=u?.name;if(c==="AbortError"||c==="NotAllowedError")return"push-service";throw u}const a=s.toJSON();if(!(await fetch("/api/push/subscribe",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({endpoint:s.endpoint,keys:{p256dh:a.keys?.p256dh,auth:a.keys?.auth},language:f()})})).ok){try{await s.unsubscribe()}catch{}return"failed"}return"subscribed"}async function m(){const i=await d();if(!i)return;const t=i.endpoint;try{await i.unsubscribe()}catch{}await fetch("/api/push/unsubscribe",{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify({endpoint:t})}).catch(()=>{})}async function r(i,t){await fetch(i,{method:"POST",credentials:"same-origin",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}).catch(()=>{})}async function k(i){await r("/api/push/preferences",{categories:i})}async function v(i){await r("/api/notifications/in-app-categories",{categories:i})}async function A(i){await r("/api/notifications/email-categories",{categories:i})}async function S(i){await r("/api/notifications/newsletter",{enabled:i})}async function C(i){await r("/api/notifications/wiki-contributions",{enabled:i})}function O(i){const t="=".repeat((4-i.length%4)%4),e=(i+t).replace(/-/g,"+").replace(/_/g,"/"),s=window.atob(e),a=new Uint8Array(s.length);for(let n=0;n<s.length;++n)a[n]=s.charCodeAt(n);return a}const h="hw.pushPromptDismissed";function M(i){i.data("pushNotifications",t=>({supported:!1,enabled:!1,permission:"default",subscribed:!1,busy:!1,ready:!1,error:!1,pushServiceOff:!1,brave:g(),dismissed:!1,publicKey:null,categories:t?.categories??t?.defaultMask??0,inApp:t?.inApp??0,lockedMask:t?.lockedMask??0,wikiBit:t?.wikiBit??0,email:t?.email??0,emailCapableMask:t?.emailCapableMask??0,emailDeliverable:t?.emailDeliverable??!1,newsletter:t?.newsletter??!1,wiki:t?.wiki??!0,get unavailable(){return!this.supported||!this.enabled},get denied(){return this.permission==="denied"},get showPrompt(){return this.ready&&this.supported&&this.enabled&&!this.subscribed&&this.permission==="default"&&!this.dismissed},async init(){try{this.dismissed=window.localStorage.getItem(h)==="1"}catch{}if(!o()){this.ready=!0;return}this.supported=!0,this.permission=l();const e=await y();if(this.enabled=e.enabled,this.publicKey=e.publicKey,e.enabled)try{await p();const s=await d();this.subscribed=!!s&&this.permission==="granted"}catch{}this.ready=!0},async enable(){if(!(this.busy||!this.publicKey)){this.busy=!0,this.error=!1,this.pushServiceOff=!1;try{const e=await w(this.publicKey);this.permission=l(),this.subscribed=e==="subscribed",this.pushServiceOff=e==="push-service",(e==="failed"||e==="not-granted"&&this.permission!=="denied")&&(this.error=!0)}catch{this.error=!0}finally{this.busy=!1}}},async disable(){if(!this.busy){this.busy=!0;try{await m(),this.subscribed=!1}finally{this.busy=!1}}}
1,async toggle(){await(this.subscribed?this.disable():this.enable())},dismissPrompt(){this.dismissed=!0;try{window.localStorage.setItem(h,"1")}catch{}},has(e){return(this.categories&e)!==0},async toggleCategory(e){this.categories=this.has(e)?this.categories&~e:this.categories|e,await k(this.categories)},hasInApp(e){return(this.inApp&e)!==0},inAppOn(e){return(this.lockedMask&e)!==0||this.hasInApp(e)},async toggleInApp(e){(this.lockedMask&e)===0&&(this.inApp=this.hasInApp(e)?this.inApp&~e:this.inApp|e,await v(this.inApp))},pushChecked(e){return this.has(e)&&this.inAppOn(e)},pushDisabled(e){return!this.subscribed||!this.inAppOn(e)},wikiPushChecked(){return(this.categories&this.wikiBit)!==0&&this.wiki},wikiPushDisabled(){return!this.subscribed||!this.wiki},emailCapable(e){return(this.emailCapableMask&e)!==0},hasEmail(e){return(this.email&e)!==0},emailChecked(e){return this.emailCapable(e)&&this.hasEmail(e)},emailDisabled(e){return!this.emailCapable(e)},async toggleEmail(e){this.emailCapable(e)&&(this.email=this.hasEmail(e)?this.email&~e:this.email|e,await A(this.email))},async toggleNewsletter(){this.newsletter=!this.newsletter,await S(this.newsletter)},async toggleWiki(){this.wiki=!this.wiki,await C(this.wiki)}}))}export{M as registerPushNotifications};

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.