1// Initialize 2importScripts('https://storage.googleapis.com/workbox-cdn/releases/4.3.0/workbox-sw.js'); 3 4// Configure 5workbox.setConfig({ debug: false }); 6 7// // Offline Google Analytics 8// workbox.googleAnalytics.initialize(); 9 10 11// Cache main pages 12workbox.routing.registerRoute( 13 /((localhost)|(urstyle\.(com|pl)\/)|(ngrok\.io\/))(\/|\/styles|\/shop)$/, 14 new workbox.strategies.NetworkFirst({ 15 cacheName: 'pages', 16 plugins: [ 17 new workbox.cacheableResponse.Plugin({ 18 statuses: [0, 200], 19 }), 20 new workbox.expiration.Plugin({ 21 maxAgeSeconds: 60 * 60 * 24 * 30, 22 }), 23 ], 24 }), 25); 26 27 28// Cache api requests 29workbox.routing.registerRoute( 30 /((localhost)|(urstyle\.(com|pl)\/)|(ngrok\.io\/))(\/api\/v1\/styles\/|\/api\/v1\/timeline\/|\/api\/v1\/products\/(shop|brands|retailers|categories|colors)\/)(\?.*)?$/, 31 new workbox.strategies.NetworkFirst({ 32 cacheName: 'api', 33 plugins: [ 34 new workbox.cacheableResponse.Plugin({ 35 statuses: [0, 200], 36 }), 37 new workbox.expiration.Plugin({ 38 maxAgeSeconds: 60 * 60 * 24 * 30, 39 }), 40 ], 41 }), 42); 43 44 45// Cache main pages 46workbox.routing.registerRoute( 47 /((localhost)|(urstyle\.(com|pl)\/)|(ngrok\.io\/))(\/login|\/categories|\/register|\/terms_of_service|\/privacy_policy|\/create|\/\?source=pwa)$/, 48 new workbox.strategies.NetworkFirst({ 49 cacheName: 'pages', 50 plugins: [ 51 new workbox.cacheableResponse.Plugin({ 52 statuses: [0, 200], 53 }), 54 new workbox.expiration.Plugin({ 55 maxAgeSeconds: 60 * 60 * 24 * 30, 56 }), 57 ], 58 }), 59); 60 61 62// Import dependencies 63importScripts('/plugins/nodebb-theme-urstyle/public/sw/sw-cache-static.js'); 64 65function displayNotification(title, body, payload) { 66 if (Notification.permission === 'granted') { 67 var options = { 68 body: body, 69 data: payload, 70 icon: '/plugins/nodebb-theme-urstyle/public/logo-round.png', 71 }; 72 return self.registration.showNotification(title, options); 73 } 74} 75 76self.addEventListener('install', function(event) { 77 event.waitUntil(self.skipWaiting()); 78}); 79 80self.addEventListener('activate', function(event) { 81 event.waitUntil(self.clients.claim()); 82}); 83 84 85self.addEventListener('push', function(event) { 86 const payload = event.data ? event.data.json() : 'no payload'; 87 88 event.waitUntil( 89 displayNotification('URSTYLE', payload.bodyTranslated, payload) 90 ); 91}); 92 93 94self.addEventListener('message', function(event){ 95 var data = JSON.parse(event.data); 96 97 self.user = data.user; 98}); 99 100self.addEventListener('notificationclick', function(e) { 101 var notification = e.notification; 102 var action = e.action; 103 104 if (action === 'close') { 105 notification.close(); 106 } else { 107 if (notification.data.path) { 108 clients.openWindow(self.origin + notification.data.path); 109 } else { 110 if (self.user){ 111 clients.openWindow(self.origin + '/user/' + self.user.username + '/chats/' + notification.data.roomId); 112 } else { 113 clients.openWindow(self.origin); 114 } 115 } 116 notification.close(); 117 } 118});
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.