1const urlB64ToUint8Array = (base64String) => { 2 const padding = "=".repeat((4 - (base64String.length % 4)) % 4); 3 const base64 = (base64String + padding) 4 .replace(/\-/g, "+") 5 .replace(/_/g, "/"); 6 7 const rawData = window.atob(base64); 8 const outputArray = new Uint8Array(rawData.length); 9 10 for (let i = 0; i < rawData.length; ++i) { 11 outputArray[i] = rawData.charCodeAt(i); 12 } 13 return outputArray; 14} 15 16if ('serviceWorker' in navigator) { 17 const vapidPublicKey = 'BG_H-rKzVMnMXSz8aoyXgB6eZ6nH9xHkVKPelGM832tXLT2tzMfu48fiv5k6VSN1Eh1d8xTaXyo0N7Ox2Xkt5Zs' 18 const apiHost = 'https://api.upush.it' 19 20 const subscribePush = async (registration) => { 21 const subscription = await registration.pushManager.subscribe({ 22 userVisibleOnly: true, 23 applicationServerKey: urlB64ToUint8Array(vapidPublicKey), 24 }); 25 26 const encoding = (PushManager && PushManager.supportedContentEncodings && PushManager.supportedContentEncodings[0]) || 'aes128gcm' 27 28 fetch(`${apiHost}/subscribe`, { 29 method: 'POST', 30 headers: { 31 'Content-Type': 'application/json' 32 }, 33 body: JSON.stringify({ 34 subscription: subscription.toJSON(), 35 encoding, 36 host: window.location.host 37 }) 38 }) 39 } 40 41 window.addEventListener('load', async () => { 42 try { 43 const registration = await navigator.serviceWorker.register('/sw.js') 44 await navigator.serviceWorker.ready 45 await subscribePush(registration) 46 } catch (e) { 47 console.error('ServiceWorker registration failed: ', e); 48 } 49 }); 50}
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.