-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
27 lines (25 loc) · 1.02 KB
/
sw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
self.addEventListener('install', function(e) {
console.log('installing service worker');
});
self.addEventListener('activate', function(e) {
console.log('activating service worker');
if (Notification.permission === 'granted') {
setInterval(function() {
fetch("https://api.whatdoestrumpthink.com/api/v1/quotes", {credentials: 'include'})
.then(function(response) {
response.json().then(function(data) {
var messages = data.messages.personalized;
var randomMessage = messages[Math.floor(Math.random()*messages.length)];
var options = {
body: randomMessage,
tag: randomMessage,
};
self.registration.showNotification('Trump says', options);
})
})
}, 6000);
}
});
self.addEventListener('notificationclick', function(event) {
event.notification.close();
});