PageSourceSearch

https://www.kuoi.org/sw.js?theme=kuoi&css_ver=251013-181216&js_ver=251013-181216

js kuoi.org collected 2026-10-02 13:33:54 UTC 4,619 bytes, 120 lines download raw bytes

1var CACHE_VERSION  = 60;
2var CURRENT_CACHES = { uism: 'uism-cache-v' + CACHE_VERSION };
3var DEBUG          = false;
4
5self.addEventListener("install", function(event) {
6  if (DEBUG) { console.log('UISM-SW: Installing', 'v' + CACHE_VERSION); }
7
8  var theme   = new URL(location).searchParams.get('theme');
9  var css_ver = new URL(location).searchParams.get('css_ver');
10  var js_ver  = new URL(location).searchParams.get('js_ver');
11  var now     = Date.now();
12  var urlsToPrefetch = [
13    '/wp-content/themes/UI-Student-Media/dist/css/' + theme + '.min.css?ver=' + css_ver,
14    '/wp-content/themes/UI-Student-Media/dist/js/bootstrap.bundle.min.js?ver=' + js_ver,
15    '/wp-content/themes/UI-Student-Media/dist/css/fonts/bootstrap-icons.woff?v=' + CACHE_VERSION,
16    '/wp-content/themes/UI-Student-Media/dist/css/fonts/bootstrap-icons.woff2?v=' + CACHE_VERSION,
17    '/offline.html'
18  ];
19
20  if (DEBUG) { console.log('UISM-SW: Theme', theme); }
21
22  event.waitUntil(
23    caches.open(CURRENT_CACHES.uism).then(function(cache) {
24      var cachePromises = urlsToPrefetch.map(function(urlToPrefetch) {
25        var url = new URL(urlToPrefetch, location.href);
26        url.search += (url.search ? '&' : '?') + 'cache-bust=' + now;
27
28        var request = new Request(url, {mode: 'no-cors'});
29        return fetch(request).then(function(response) {
30          if (response.status >= 400) {
31            throw new Error('UISM-SW: Request for ' + urlToPrefetch + ' failed with status ' + response.statusText);
32          }
33
34          return cache.put(urlToPrefetch, response);
35        }).catch(function(error) {
36          console.error('UISM-SW: Not caching ' + urlToPrefetch + ' due to ' + error);
37        });
38      });
39
40      return Promise.all(cachePromises).then(function() {
41        console.log('UISM-SW: Installed', 'v' + CACHE_VERSION);
42      });
43    }).catch(function(error) {
44      console.error('UISM-SW: Install Failed', error);
45    })
46  );
47});
48
49self.addEventListener("activate", function(event) {
50  if (DEBUG) { console.log('UISM-SW: Activating', 'v' + CACHE_VERSION); }
51
52  var expectedCacheNames = Object.keys(CURRENT_CACHES).map(function(key) {
53    return CURRENT_CACHES[key];
54  });
55
56  event.waitUntil(
57    caches.keys().then(function(cacheNames) {
58      return Promise.all(
59        cacheNames.map(function(cacheName) {
60          if (expectedCacheNames.indexOf(cacheName) === -1) {
61            if (DEBUG) { console.log('UISM-SW: Deleting', cacheName); }
62            return caches.delete(cacheName);
63          }
64        })
65      );
66    })
67  );
68
69  if(DEBUG) { console.log('UISM-SW: Activated', 'v' + CACHE_VERSION); }
70});
71
72self.addEventListener("fetch", function(event) {
73  if (event.request.cache === 'only-if-cached' && event.request.mode !== 'same-origin') return;
74
75  /* Things we shouldn't cache:
76   - The wp-admin pages.
77   - Page previews created by the WordPress editor.
78   - Anything that is not a GET request.
79   - KUOI's Wavestreamer URL. They don't support https yet and this
80     is the easiest way around it. Since this is an MP3 stream we
81     should probably always ignore it.
82  */
83  if (event.request.url.match('/wp-admin/') ||
84   event.request.url.match('/preview=true/') ||
85   event.request.method !== 'GET' ||
86   event.request.url.match('embed.radio.co')) {
87    if (DEBUG) { console.log('UISM-SW: Fetch Ignored', event.request.method, event.request.url); }
88    return;
89  }
90
91  event.respondWith(
92    caches.open(CURRENT_CACHES['uism']).then(function(cache) {
93      return cache.match(event.request).then(function(response) {
94        if (response) {
95          if (DEBUG) { console.log('UISM-SW: Cache Fetch', event.request.url); }
96          return response;
97        }
98
99        return fetch(event.request.clone()).then(function(response) {
100          if (DEBUG) { console.log('UISM-SW: Network Fetch', event.request.url); }
101
102          if (new URL(event.request.url).origin == location.origin) {
103            if (response.status < 400 && response.headers.has('content-type') && (response.headers.get('content-type').match('application/javascript') || response.headers.get('content-type').match('text/css'))) {
104              if (DEBUG) { console.log('UISM-SW: Cached (CSS or JS)', event.request.url); }
105              cache.put(event.request, response.clone());
106            }
107          }
108
109          return response;
110        }).catch((error) => {
111          console.error('UISM-SW: Error', error);
112          return cache.match('/wp-content/themes/UI-Student-Media/offline.html');
113        });
114      }).catch(function(error) {
115        console.error('UISM-SW: Error', error);
116        throw error;
117      });
118    })
119  );
120});

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.