PageSourceSearch

https://drechsler-umweltschutz.de/pwa.sw.js

js drechsler-umweltschutz.de collected 2026-10-06 19:58:04 UTC 3,217 bytes, 101 lines download raw bytes

1
2'use strict';
3
4let dataCacheName = 'wswPwaCacheData-v1';
5let isEnabled = true;
6
7self.addEventListener('install', function(e) {
8    console.log('[ServiceWorker] Install');
9});
10
11self.addEventListener('activate', function(e) {
12    console.log('[ServiceWorker] Activate');
13    return self.clients.claim();
14});
15
16self.addEventListener('fetch', function(e) {
17    if (
18        !isEnabled ||
19        e.request.url.indexOf('/admin/') !== -1 ||
20        e.request.url.indexOf('/files/') !== -1 ||
21        (e.request.cache === 'only-if-cached' && e.request.mode !== 'same-origin') ||
22        !e.request.url.startsWith('http') ||
23        e.request.method === 'POST'
24    ) {
25        return;
26    }
27
28    let forceCache = () => {
29        return caches.open(dataCacheName).then(function (cache) {
30            return fetch(e.request).then(function (response) {
31                cache.put(e.request.url, response.clone());
32                return response;
33            }).catch(function (error) {
34                return caches.match(e.request).then(function (response) {
35                    if (response) {
36                        return response;
37                    }
38                });
39            });
40        })
41    };
42
43    if(e.request.url.includes('/build/') && (e.request.url.endsWith('.js') || e.request.url.endsWith('.css'))) {
44        e.respondWith(
45            caches.match(e.request).then(function(response) {
46                if(response) {
47                    return response;
48                } else {
49                    return forceCache();
50                }
51            })
52        );
53    } else {
54        e.respondWith(
55            forceCache()
56        );
57    }
58});
59
60self.addEventListener('push', function(event) {
61    // [Service Worker] Push had this data: "${event.data.text()}"`
62
63    let subject, redirectLink;
64    const options = {};
65
66    if(event.data.text().startsWith('{')) {
67        let receivedData = JSON.parse(event.data.text());
68        subject = (receivedData && receivedData.subject) ? receivedData.subject : null;
69        options.body = (receivedData && receivedData.body) ? receivedData.body : null;
70        redirectLink = (receivedData && receivedData.redirect) ? receivedData.redirect : null;
71
72        if(receivedData && receivedData.icon) options.icon = receivedData.icon;
73        if(receivedData && receivedData.badge) options.badge = receivedData.badge;
74        if(receivedData && receivedData.image) options.image = receivedData.image;
75    } else {
76        options.body = event.data.text();
77        redirectLink = null;
78    }
79
80    const title = subject ? subject : '';
81    options.data = { redirectLink: redirectLink };
82
83    event.waitUntil(self.registration.showNotification(title, options));
84});
85
86self.addEventListener('notificationclick', function(event) {
87    event.notification.close();
88
89    let link = (event.notification && event.notification.data && event.notification.data.redirectLink) ?
90        event.notification.data.redirectLink : '';
91
92    event.waitUntil(
93        clients.openWindow(link)
94    );
95});
96
97self.addEventListener("message", function(e) {
98    try {
99        if(e && e.data && typeof e.data !== 'string' && e.data.forceDisable) isEnabled = false;
100    } catch(err) {}
101}, false);

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.