PageSourceSearch

https://050f.bet/firebase-messaging-sw.js

js 050f.bet collected 2026-10-09 04:39:53 UTC 3,656 bytes, 108 lines download raw bytes

1// 使用 importScripts 加载 Firebase SDK
2/* eslint-disable no-undef */
3
4importScripts('https://www.gstatic.com/firebasejs/9.14.0/firebase-app-compat.js');
5importScripts('https://www.gstatic.com/firebasejs/9.14.0/firebase-messaging-compat.js');
6
7const isLocalServer = () => {
8  const hostname = self.location.hostname;
9  if (hostname === 'localhost') {
10    return true;
11  } else {
12    return /\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}/.test(hostname);
13  }
14};
15
16const getCurrentDomain = () => {
17  if (isLocalServer()) {
18    return 'https://website.br3600.com';
19  } else {
20    return self.location.origin.replace(/^https?:\/\/(?:www\.|m\.)?/, '//website.');
21  }
22};
23
24console.log('Current domain:', getCurrentDomain());
25
26self.addEventListener('notificationclick', (event) => {
27  console.log('当点击通知时:', event);
28  event.notification.close();
29  event.waitUntil(
30    clients.openWindow(self.location.origin), // Open the URL associated with the notification
31  );
32
33  const notificationData = event?.notification?.data?.FCM_MSG;
34  if (notificationData) {
35    const currentDomain = self.location.origin.replace(/^https?:\/\/(?:www\.)?/, '//website.');
36    console.log('Current domain:', currentDomain);
37    // Send a POST request to the server to report the click
38    fetch(`${currentDomain}/task/message/view`, {
39      method: 'POST',
40      headers: {
41        'Content-Type': 'application/json',
42      },
43      body: JSON.stringify({
44        task_id: notificationData.data.task_id,
45        message_id: notificationData.fcmMessageId,
46      }),
47    })
48      .then((res) => {
49        console.error(res);
50      })
51      .catch((error) => {
52        console.error('Error reporting click:', error);
53      });
54  }
55
56  // 这会查看当前标签页是否已打开并是否已聚焦
57  // event.waitUntil(
58  //   clients
59  //     .matchAll({
60  //       type: 'window',
61  //     })
62  //     .then((clientList) => {
63  //       for (const client of clientList) {
64  //         if (client.url === '/' && 'focus' in client) return client.focus();
65  //       }
66  //       if (clients.openWindow) return clients.openWindow('/');
67  //     }),
68  // );
69});
70
71
72
73const firebaseConfig = JSON.parse("{\"apiKey\":\"AIzaSyAyu8D-M_kF1VhdUVbiFuhGrkJUe7XpyoY\",\"appId\":\"1:1013856022208:web:d62cd42db5e79f9be48725\",\"authDomain\":\"pgwin-366f2.firebaseapp.com\",\"measurementId\":\"G-6MFL4NYJ3X\",\"messagingSenderId\":\"1013856022208\",\"projectId\":\"pgwin-366f2\",\"storageBucket\":\"pgwin-366f2.firebasestorage.app\"}");
74
75
76
77firebase.initializeApp(firebaseConfig);
78
79const messaging = firebase.messaging();
80
81// If you would like to customize notifications that are received in the
82// background (Web app is closed or not in browser focus) then you should
83// implement this optional method.
84// Keep in mind that FCM will still show notification messages automatically
85// and you should use data messages for custom notifications.
86// For more info see:
87// https://firebase.google.com/docs/cloud-messaging/concept-options
88
89messaging.onBackgroundMessage((payload) => {
90  console.log(JSON.stringify(payload));
91  if (payload && payload.data && payload.data.title) {
92    const payloadData = payload.data;
93    const notificationTitle = payloadData.title;
94    const notificationOptions = {
95      body: payloadData.body,
96      icon: payloadData.icon,
97      image: payloadData.image,
98      data: {
99        task_id: payloadData.task_id,
100        click_action: payloadData.click_action,
101        message_id: payload.messageId,
102      },
103    };
104    self.registration.showNotification(notificationTitle, notificationOptions);
105  } else {
106    console.log('收到的消息内容无效:', payload);
107  }
108});

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.