chart.js
1 week ago
check-mail-jsPdf.js
1 week ago
check_mail_push.js
1 week ago
check_mail_wizard.js
1 week ago
check_mail_wizard.min.js
1 week ago
checkemail.js
1 week ago
checkemail.min.js
1 week ago
checkmail-dashboard-chart.js
1 week ago
checkmail-dashboard-chart.min.js
1 week ago
checkmail-sw.js
1 week ago
ck_mail-newsletter-script.js
1 week ago
ck_mail-newsletter-script.min.js
1 week ago
export-logs.js
1 week ago
export-logs.min.js
1 week ago
feedback.js
1 week ago
feedback.min.js
1 week ago
firebase-app.js
1 week ago
firebase-messaging.js
1 week ago
support-settings.js
1 week ago
support-settings.min.js
1 week ago
view-logs.js
1 week ago
view-logs.min.js
1 week ago
checkmail-sw.js
95 lines
| 1 | |
| 2 | |
| 3 | importScripts("https://www.gstatic.com/firebasejs/7.8.2/firebase-app.js"); |
| 4 | importScripts("https://www.gstatic.com/firebasejs/7.8.2/firebase-analytics.js"); |
| 5 | importScripts("https://www.gstatic.com/firebasejs/7.8.2/firebase-messaging.js"); |
| 6 | |
| 7 | const firebaseConfig = { |
| 8 | apiKey: "AIzaSyDhRbFy9m-NXZVkozYJwKdDYJuwsL6W_bw", |
| 9 | authDomain: "pushnotificationsio.firebaseapp.com", |
| 10 | projectId: "pushnotificationsio", |
| 11 | messagingSenderId: "788493704860", |
| 12 | appId: "1:788493704860:web:ba71fd692e7cc9651f5759" |
| 13 | }; |
| 14 | |
| 15 | |
| 16 | if (!firebase.apps.length) {firebase.initializeApp(firebaseConfig);} |
| 17 | const messaging = firebase.messaging(); |
| 18 | var messageCount = 0; |
| 19 | var unreadCount = 0; |
| 20 | |
| 21 | messaging.setBackgroundMessageHandler(function(payload) { |
| 22 | const notificationTitle = payload.data.title; |
| 23 | const notificationOptions = { |
| 24 | body: payload.data.body, |
| 25 | icon: payload.data.icon, |
| 26 | image: payload.data.image, |
| 27 | vibrate: [100, 50, 100], |
| 28 | data: { |
| 29 | dateOfArrival: Date.now(), |
| 30 | primarykey: payload.data.currentCampaign, |
| 31 | url : payload.data.url |
| 32 | }, |
| 33 | } |
| 34 | messageCount += 1; |
| 35 | setBadge(messageCount); |
| 36 | |
| 37 | return self.registration.showNotification(notificationTitle, notificationOptions); |
| 38 | }); |
| 39 | |
| 40 | |
| 41 | self.addEventListener("notificationclose", function(e) { |
| 42 | var notification = e.notification; |
| 43 | var primarykey = notification.data.primarykey; |
| 44 | messageCount -= 1; |
| 45 | unreadCount -= 1; |
| 46 | if(messageCount>0 && unreadCount > 0){ |
| 47 | setBadge(messageCount); |
| 48 | }else{ |
| 49 | clearBadge(); |
| 50 | } |
| 51 | }); |
| 52 | |
| 53 | self.addEventListener("notificationclick", function(e) { |
| 54 | var notification = e.notification; |
| 55 | messageCount -= 1; |
| 56 | unreadCount -= 1; |
| 57 | notification.close(); |
| 58 | }); |
| 59 | |
| 60 | |
| 61 | |
| 62 | |
| 63 | function setBadge(...args) { |
| 64 | if (navigator.setAppBadge) { |
| 65 | navigator.setAppBadge(...args); |
| 66 | } else if (navigator.setExperimentalAppBadge) { |
| 67 | navigator.setExperimentalAppBadge(...args); |
| 68 | } else if (window.ExperimentalBadge) { |
| 69 | window.ExperimentalBadge.set(...args); |
| 70 | } |
| 71 | } |
| 72 | |
| 73 | // Wrapper to support first and second origin trial |
| 74 | // See https://web.dev/badging-api/ for details. |
| 75 | function clearBadge() { |
| 76 | if (navigator.clearAppBadge) { |
| 77 | navigator.clearAppBadge(); |
| 78 | } else if (navigator.clearExperimentalAppBadge) { |
| 79 | navigator.clearExperimentalAppBadge(); |
| 80 | } else if (window.ExperimentalBadge) { |
| 81 | window.ExperimentalBadge.clear(); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | self.addEventListener("push", (event) => { |
| 86 | unreadCount += 1; |
| 87 | // Set or clear the badge. |
| 88 | if (navigator.setAppBadge) { |
| 89 | if (unreadCount && unreadCount > 0) { |
| 90 | navigator.setAppBadge(unreadCount); |
| 91 | } else { |
| 92 | navigator.clearAppBadge(); |
| 93 | } |
| 94 | } |
| 95 | }); |