PageSourceSearch

https://www.commune-nointel.fr/koba-sw.js

js commune-nointel.fr collected 2026-10-03 02:46:44 UTC 3,122 bytes, 90 lines download raw bytes

1// Koba Service Worker — v1.0.1
2
3self.addEventListener('install', function(event) {
4    self.skipWaiting();
5});
6
7self.addEventListener('activate', function(event) {
8    event.waitUntil(self.clients.claim());
9});
10
11// ============ PUSH ============
12self.addEventListener('push', function(event) {
13    var data = {};
14    if (event.data) {
15        try { data = event.data.json(); }
16        catch (e) {
17            try { data = { title: 'Notification', body: event.data.text() }; }
18            catch (e2) { data = { title: 'Notification', body: '' }; }
19        }
20    }
21
22    var title = data.title || 'Notification';
23    var defaultIcon = 'https://www.commune-nointel.fr/wp-content/themes/hob-koba-civique/images/kobacivique-hob.png';
24
25    // Sur iOS, "image" est ignoré → on privilégie l'image jointe comme "icon"
26    var notifIcon = data.image || data.icon || defaultIcon;
27
28    var options = {
29        body:  data.body  || '',
30        icon:  notifIcon,
31        badge: defaultIcon,
32        data:  {
33            url:      data.url      || 'https://www.commune-nointel.fr/app/',
34            notif_id: data.notif_id || 0,
35        },
36        requireInteraction: false,
37        vibrate: [200, 100, 200],
38    };
39
40    // Sur Android, on ajoute aussi "image" pour la grande bannière
41    if (data.image) options.image = data.image;
42
43    event.waitUntil(self.registration.showNotification(title, options));
44});
45
46// ============ CLIC SUR NOTIFICATION ============
47self.addEventListener('notificationclick', function(event) {
48    event.notification.close();
49
50    var targetUrl = (event.notification.data && event.notification.data.url) || 'https://www.commune-nointel.fr/app/';
51    var notifId   = (event.notification.data && event.notification.data.notif_id) || 0;
52
53    // URL absolue obligatoire pour iOS — si pas de scheme, on préfixe l'origine
54    if (targetUrl && !/^https?:\/\//i.test(targetUrl)) {
55        targetUrl = self.location.origin + (targetUrl.charAt(0) === '/' ? '' : '/') + targetUrl;
56    }
57
58    // Ping serveur pour marquer comme lue (étape 2)
59    var markReadPromise = Promise.resolve();
60if (notifId) {
61    markReadPromise = fetch('https://www.commune-nointel.fr/wp-admin/admin-ajax.php?action=koba_push_mark_read&notif_id=' + notifId, {
62        method: 'POST',
63        credentials: 'include',
64    }).catch(function(){});
65}
66
67event.waitUntil(
68    Promise.all([
69        markReadPromise,
70        clients.matchAll({ type: 'window', includeUncontrolled: true }).then(function(clientList) {
71            // ...reste du code identique
72            for (var i = 0; i < clientList.length; i++) {
73                var c = clientList[i];
74                var url = new URL(c.url);
75                if (url.origin === self.location.origin) {
76                    if ('focus' in c) {
77                        c.focus();
78                        c.postMessage({ type: 'koba_notif_navigate', url: targetUrl });
79                        return;
80                    }
81                }
82            }
83            if (clients.openWindow) {
84                return clients.openWindow(targetUrl);
85            }
86        })
87    ])
88);
89});
90    

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.