PageSourceSearch

https://www.kits.com/js/shared/initialize-sw.js

js kits.com collected 2026-09-28 08:07:25 UTC 3,394 bytes, 102 lines download raw bytes

1function registerToken(currentToken) {
2  return fetch("/firebase/register", {
3    method: "POST",
4    body: JSON.stringify({
5      browserToken: currentToken
6    }),
7    headers: {
8      "Content-type": "application/json; charset=UTF-8"
9    }
10  })
11}
12
13function registerTokenPostLogin(currentToken) {
14  return fetch("/firebase/register/postlogin", {
15    method: "POST",
16    body: JSON.stringify({
17      browserToken: currentToken
18    }),
19    headers: {
20      "Content-type": "application/json; charset=UTF-8"
21    }
22  })
23}
24
25function initSW() {
26  if ('serviceWorker' in navigator) {
27    navigator.serviceWorker.register('/js/shared/firebase-messaging-sw.js')
28      .then(function (registration) {
29        // Registration was successful
30        registration.update();
31
32        const firebaseConfig = {
33          apiKey: "AIzaSyC7LDac6922vJrPgktG_6kGcIbwjHAHiIA",
34          authDomain: "kits--production.firebaseapp.com",
35          projectId: "kits--production",
36          storageBucket: "kits--production.appspot.com",
37          messagingSenderId: "25471562052",
38          appId: "1:25471562052:web:47ea2ac49bb32aa43ee711",
39          measurementId: "G-1X43LSPGCL"
40        };
41
42        if (firebase.apps.length == 0) {
43          // Initialize Firebase
44          firebase.initializeApp(firebaseConfig);
45
46          firebase.analytics();
47        }
48
49
50        const messaging = firebase.messaging();
51
52        messaging.getToken({ serviceWorkerRegistration: registration, vapidKey: "BD5oOY3ixlPeG_2qxy6EALk9yuRtekh_R27IZ9e4IE0fO8hq3hAf_NLFyAtI_Rg_3xGitUxgiD67YUDihE7SeK0" })
53          .then((currentToken) => {
54            localStorage.currentToken = currentToken;
55            if (currentToken) {
56              let sessionUsername = sessionStorage.getItem('username') || '';
57              // Send the token to your server and update the UI if necessary
58              if ((sessionUsername && sessionUsername.trim().length>0) || window.hasCheckedOutOrPurchased) {
59                registerTokenPostLogin(currentToken);
60                if (window.hasCheckedOutOrPurchased) window.hasCheckedOutOrPurchased = !window.hasCheckedOutOrPurchased;
61              } else {
62                registerToken(currentToken);
63              }
64            } else {
65              // Show permission request UI
66              console.log('No registration token available. Request permission to generate one.');
67            }
68          }).catch((err) => {
69            console.log('An error occurred while retrieving token. ', err);
70          });
71      }, function (err) {
72        // registration failed :(
73        console.log('ServiceWorker registration failed: ', err);
74      })
75  }
76}
77
78function checkAndLoadSW() {
79  if (!("Notification" in window)) {
80    console.warn("This browser does not support notification");
81  }
82  // Let's check whether notification permissions have already been granted
83  else if (Notification.permission === "granted") {
84    // If it's okay let's create a notification
85    initSW();
86  }
87  // Otherwise, we need to ask the user for permission
88  else if (Notification.permission !== "denied") {
89    Notification.requestPermission().then(function (permission) {
90      // If the user accepts, let's create a notification
91      if (permission === "granted") {
92        initSW();
93      }
94    });
95  }
96}
97
98window.addEventListener('load', function () {
99  checkAndLoadSW();
100});
101
102window.hasCheckedOutOrPurchased = 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.