Website : rimsha.abasa.com
backdoor
Home
Console
Upload
information
Create File
Create Folder
About
Tools
:
/
var
/
www
/
mudeer-web-backup30April26
/
public
/
Filename :
firebase-messaging-sw.js
back
Copy
// Firebase Messaging Service Worker importScripts('https://www.gstatic.com/firebasejs/10.7.1/firebase-app-compat.js'); importScripts('https://www.gstatic.com/firebasejs/10.7.1/firebase-messaging-compat.js'); // Initialize Firebase in the service worker const firebaseConfig = { apiKey: "AIzaSyCbIvnNxswOK6arm8KtSgItNloq-SuHq5w", authDomain: "webnexus-proj.firebaseapp.com", projectId: "webnexus-proj", storageBucket: "webnexus-proj.firebasestorage.app", messagingSenderId: "272445720449", appId: "1:272445720449:web:9df3873d05069c65f68a80", measurementId: "G-ZG6XN7KYRH" }; firebase.initializeApp(firebaseConfig); const messaging = firebase.messaging(); // Handle background messages (when tab is not focused) messaging.onBackgroundMessage(function(payload) { console.log('[Service Worker] Background message received:', payload); let notificationTitle = payload.notification?.title || 'Mudeer Login Alert'; let notificationBody = payload.notification?.body || 'Employee login notification'; // Special handling for late arrival notifications if (payload.data?.type === 'late_notification' && payload.data?.expectedStartTime) { try { // Convert KSA time to local time const ksaTimeString = payload.data.expectedStartTime; const [time, modifier] = ksaTimeString.split(' '); const [hoursRaw, minutes] = time.split(':').map(Number); let hours = hoursRaw; // Convert to 24-hour format const modifierLower = modifier?.toLowerCase(); if (modifierLower === 'pm' && hours !== 12) hours += 12; if (modifierLower === 'am' && hours === 12) hours = 0; // Create date in UTC (KSA is UTC+3, so subtract 3 hours) const now = new Date(); const utcDate = new Date(Date.UTC( now.getUTCFullYear(), now.getUTCMonth(), now.getUTCDate(), hours - 3, minutes, 0, 0 )); // Convert to local time string const localTimeString = utcDate.toLocaleString(undefined, { hour: 'numeric', minute: '2-digit', hour12: true }); // Reconstruct the notification body with local time const userName = payload.data.userName || 'Employee'; const department = payload.data.department; const departmentText = department ? ` from ${department}` : ''; notificationBody = `${userName}${departmentText} has not checked in yet. Expected at ${localTimeString}`; } catch (error) { console.error('[Service Worker] Error converting time:', error); // Fall back to original body if conversion fails } } const notificationOptions = { body: notificationBody, icon: '/icon-192x192.png', badge: '/icon-192x192.png', data: payload.data, requireInteraction: true, tag: 'mudeer-login', actions: [ { action: 'view', title: 'View Dashboard' } ] }; return self.registration.showNotification(notificationTitle, notificationOptions); }); // Handle notification clicks self.addEventListener('notificationclick', function(event) { console.log('[Service Worker] Notification clicked:', event); event.notification.close(); if (event.action === 'view' || !event.action) { event.waitUntil( clients.openWindow('/employees') ); } });