-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathupup.sw.min.js
92 lines (75 loc) · 2.94 KB
/
upup.sw.min.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
//! UpUp Service Worker
//! version : 0.3.0
//! author : Tal Ater @TalAter
//! license : MIT
//! https://github.com/TalAter/UpUp
var _CACHE_NAME_PREFIX = "upup-cache",
_calculateHash = function(a) {
a = a.toString();
var b, c, d = 0,
e = a.length;
if (0 === e) return d;
for (b = 0; b < e; b++) c = a.charCodeAt(b), d = (d << 5) - d + c, d |= 0;
return d
};
self.addEventListener("message", function(a) {
"set-settings" === a.data.action && _parseSettingsAndCache(a.data.settings)
}), self.addEventListener("fetch", function(a) {
a.respondWith(fetch(a.request).catch(function() {
return caches.match(a.request).then(function(b) {
return b || ("navigate" === a.request.mode || "GET" === a.request.method && a.request.headers.get("accept").includes("text/html") ? caches.match("sw-offline-content") : void 0)
})
}))
});
var _parseSettingsAndCache = function(a) {
var b = _CACHE_NAME_PREFIX + "-" + (a["cache-version"] ? a["cache-version"] + "-" : "") + _calculateHash(a.content + a["content-url"] + a.assets);
return caches.open(b).then(function(b) {
return a.assets && b.addAll(a.assets.map(function(a) {
return new Request(a, {
mode: "no-cors"
})
})), a["content-url"] ? fetch(a["content-url"], {
mode: "no-cors"
}).then(function(a) {
return b.put("sw-offline-content", a)
}) : a.content ? b.put("sw-offline-content", _buildResponse(a.content)) : b.put("sw-offline-content", _buildResponse("You are offline"))
}).then(function() {
return caches.keys().then(function(a) {
return Promise.all(a.map(function(a) {
if (a.startsWith(_CACHE_NAME_PREFIX) && b !== a) return caches.delete(a)
}))
})
})
},
_buildResponse = function(a) {
return new Response(a, {
headers: {
"Content-Type": "text/html"
}
})
};
//# sourceMappingURL=upup.sw.min.js.map
self.addEventListener('push', function(event) {
console.log('[Service Worker] Push Received.');
console.log(`[Service Worker] Push had this data: "${event.data.text()}"`);
const title = 'The school №14';
const options = {
body: event.data.text(),
icon: '/public/img/logo-192x192.png',
badge: '/public/img/badge-72x72.png'
};
event.waitUntil(self.registration.showNotification(title, options));
});
self.addEventListener('notificationclick', function(event) {
console.log('[Service Worker] Notification click Received.');
event.notification.close();
event.waitUntil(
clients.openWindow('http://localhost:8080')
);
});
/* eslint-env browser, serviceworker */
// Until(
// clients.openWindow('http://localhost:8080')
// );
// });
/* eslint-env browser, serviceworker */