-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
37 lines (28 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
28
29
30
31
32
33
34
35
36
37
'use strict';
importScripts('scripts/sw-toolbox.js');
toolbox.precache(["index.html", "manifest.json", "browserconfig.xml", "icons/pwa.svg"]);
toolbox.router.get("icons/*", toolbox.cacheFirst);
toolbox.router.get("screenshots/*", toolbox.cacheFirst);
toolbox.router.get("scripts/*", toolbox.cacheFirst);
toolbox.router.get("css/*", toolbox.cacheFirst);
toolbox.router.get("./*", toolbox.networkFirst, {
networkTimeoutSeconds: 5
});
addEventListener('install', event => {
skipWaiting();
});
addEventListener('activate', event => {
clients.claim();
});
addEventListener('fetch', event => {
if (event.request.method !== 'POST' || !event.request.url.includes('share.html')) {
return;
}
event.respondWith(Response.redirect('index.html'));
event.waitUntil(async function() {
const data = await event.request.formData();
const client = await self.clients.get(event.resultingClientId || event.clientId);
const file = data.get('plainText');
client.postMessage({ file, action: 'accept-shared' });
}());
});