1(() => { 2 "use strict"; 3 importScripts( 4 './sw/sw-moudules.utils.js', // å·¥å ·å½æ° 5 './sw/sw-moudules.domain.js', // åå忢ç¸å ³ 6 './sw/sw-moudules.page.js', // åååæ¢é¡µé¢ 7 './sw/sw-moudules.webpush.js', // æå ç¸å ³å½æ° 8 ); 9 10 11 self.addEventListener("install", event => { 12 event.waitUntil(self.skipWaiting()); 13 }), 14 15 self.addEventListener("fetch", event => { 16 // é¿å å¤çéåæºè¯·æ± 17 const url = new URL(event.request.url); 18 if (event.request.method !== 'GET' || url.origin !== self.location.origin) return; 19 if (url.pathname.includes('/api/') || url.pathname.includes('.')) { // é¿å å¤ç api 请æ±åéæèµæºè¯·æ± 20 return; 21 } 22 // å¤çcåå 23 event.respondWith( 24 (async () => { 25 try { 26 const networkResponse = await fetch(event.request); 27 if (networkResponse.ok) { 28 return networkResponse; 29 } 30 // 妿ç½ç»ååºä¸æ£å¸¸ï¼æåºé误è¿å ¥ catch å 31 throw new Error('network error when fetching request'); 32 } catch (err) { 33 // è®°å½éè¯¯ï¼æ¿æ¢ä¸ºä½ èªå·±çé误æ¥å¿å½æ°ï¼ 34 console.error('请æ±å¤±è´¥:', err); 35 36 if (!navigator.onLine) { 37 // 离线ï¼è¿åèªå®ä¹ç¦»çº¿é¡µé¢ 38 return new Response( 39 '<h1>navigator is offLine,Please check the device network</h1>', 40 { 41 status: 503, 42 headers: { 'Content-Type': 'text/html' }, 43 } 44 ); 45 } else { 46 // å¨çº¿ï¼çæå¹¶ç¼åå¨æé¡µé¢ 47 const htmlContent = createDynamicOnlinePage(buildStringMap()); 48 // 弿¥ç¼åååº 49 try { 50 const cache = await caches.open('online-page'); 51 const cacheRequest = new Request(self.location.origin + '/sw-page.html'); 52 await cache.put(cacheRequest, htmlContent.clone()); 53 } catch (cacheError) { 54 console.error('ç¼å失败:', cacheError); 55 } 56 57 // ä¼å è¿åæ°çæçååºï¼æä»ç¼åä¸è·å 58 const cacheRequest = new Request(self.location.origin + '/sw-page.html'); 59 const cachedResponse = await caches.match(cacheRequest); 60 console.log(cachedResponse,'cachedResponse') 61 return cachedResponse || htmlContent; 62 } 63 } 64 })() 65 ); 66 }), 67 self.addEventListener("message", async function (t) { 68 const e = t.data || { code: 0, msg: {} }; 69 var n; 70 9999 === e.code && 71 ((n = e.msg), 72 s("https://webpushstat.api.engagelab.cc/v4/web/report", n.data, { 73 headers: { Authorization: n.Authorization }, 74 })), 75 6666 === t.data.code && 76 a( 77 [{ type: "msg_status", msg_id: e.msg.msg_id, result: 3018 }], 78 e.msg 79 ); 80 }), 81 self.addEventListener("notificationclick", function (t) { 82 const e = t.notification.data; 83 if (e) { 84 const s = "MTPush" === e.engagelab_mesg_type ? "MTPush" : "W3Push"; 85 a( 86 [{ type: "msg_status", msg_id: t.notification.tag, result: 3002 }], 87 e, 88 s 89 ); 90 let n = null == e ? void 0 : e.engagelab_url; 91 t.action && 92 e.engagelab_action_urls && 93 e.engagelab_action_urls[t.action] && 94 (n = e.engagelab_action_urls[t.action]), 95 n && 96 (n.includes('redirect=') ? n = self.location.origin + n.split('redirect=')[1] + '?timestamp=' + new Date().getTime() : 97 n = self.location.origin, console.log('跳转页é¢:', n), t.notification.close(), t.waitUntil(self.clients.openWindow(n))); 98 } 99 }), 100 self.addEventListener("push", function (t) { 101 if (!t.data) return; 102 const e = t.data.json(); 103 var s; 104 if (e.locationTestDempWebPush52755665) 105 self.registration.showNotification(e.title, e); 106 else if ( 107 (a([{ type: "msg_status", msg_id: e.tag, result: 3001 }], e.data), 108 self.clients.matchAll().then((t) => { 109 t && 110 t.length && 111 t.forEach((t) => { 112 t.postMessage(e); 113 }); 114 }), 115 (s = e.data.ntf_or_msg) && (1 === s || 3 === s)) 116 ) { 117 a([{ type: "msg_status", msg_id: e.tag, result: 3018 }], e.data); 118 const s = self.registration.showNotification(e.title, e); 119 t.waitUntil(s); 120 } 121 } 122 ); 123 self.addEventListener("activate", event => { 124 event.waitUntil(self.clients.claim()); 125 }); 126})(); 127
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.