PageSourceSearch

https://www.jianyingchinese.com/sw.js

js jianyingchinese.com collected 2026-10-02 15:42:27 UTC 1,743 bytes, 68 lines download raw bytes

1// Service Worker for Push Notifications
2// This file must be in the public folder to be accessible at the root
3
4self.addEventListener('push', function (event) {
5  if (!event.data) return
6
7  const data = event.data.json()
8
9  const options = {
10    body: data.body || 'You have a new message',
11    icon: '/icon.png',
12    badge: '/icon.png',
13    tag: data.tag || 'chat-notification',
14    data: {
15      url: data.url || '/my-home',
16      conversationId: data.conversationId,
17    },
18    actions: [
19      {
20        action: 'open',
21        title: 'Open Chat',
22      },
23      {
24        action: 'dismiss',
25        title: 'Dismiss',
26      },
27    ],
28    requireInteraction: false,
29    vibrate: [200, 100, 200],
30  }
31
32  event.waitUntil(self.registration.showNotification(data.title || 'New Message', options))
33})
34
35self.addEventListener('notificationclick', function (event) {
36  event.notification.close()
37
38  if (event.action === 'dismiss') {
39    return
40  }
41
42  // Open the app or focus if already open
43  const urlToOpen = event.notification.data?.url || '/my-home'
44
45  event.waitUntil(
46    clients
47      .matchAll({type: 'window', includeUncontrolled: true})
48      .then(function (clientList) {
49        // Check if there's already a window open
50        for (const client of clientList) {
51          if (client.url.includes(self.location.origin) && 'focus' in client) {
52            client.focus()
53            client.navigate(urlToOpen)
54            return
55          }
56        }
57        // If no window is open, open a new one
58        if (clients.openWindow) {
59          return clients.openWindow(urlToOpen)
60        }
61      })
62  )
63})
64
65// Handle service worker activation
66self.addEventListener('activate', function (event) {
67  event.waitUntil(clients.claim())
68})

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.