diff --git a/icons/icon-192.png b/icons/icon-192.png new file mode 100644 index 0000000..e5c98f6 Binary files /dev/null and b/icons/icon-192.png differ diff --git a/icons/icon-512.png b/icons/icon-512.png new file mode 100644 index 0000000..5109708 Binary files /dev/null and b/icons/icon-512.png differ diff --git a/index.html b/index.html index 810588c..b667f0c 100644 --- a/index.html +++ b/index.html @@ -4,6 +4,9 @@ Hogwarts Arithmancy v15 + + + @@ -117,5 +120,14 @@ + diff --git a/manifest.webmanifest b/manifest.webmanifest new file mode 100644 index 0000000..460f02c --- /dev/null +++ b/manifest.webmanifest @@ -0,0 +1,20 @@ +{ + "name": "Hogwarts Arithmancy", + "short_name": "Arithmancy", + "start_url": "./", + "display": "standalone", + "background_color": "#0c0b0b", + "theme_color": "#740001", + "icons": [ + { + "src": "icons/icon-192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "icons/icon-512.png", + "sizes": "512x512", + "type": "image/png" + } + ] +} diff --git a/service-worker.js b/service-worker.js new file mode 100644 index 0000000..2dced7b --- /dev/null +++ b/service-worker.js @@ -0,0 +1,51 @@ +const CACHE_NAME = 'arithmancy-pwa-v1'; +const ASSETS = [ + './', + './index.html', + './style.css', + './app.js', + './manifest.webmanifest', + './icons/icon-192.png', + './icons/icon-512.png' +]; + +self.addEventListener('install', (event) => { + event.waitUntil( + caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS)) + ); + self.skipWaiting(); +}); + +self.addEventListener('activate', (event) => { + event.waitUntil( + caches.keys().then((keys) => + Promise.all(keys.filter((key) => key !== CACHE_NAME).map((key) => caches.delete(key))) + ) + ); + self.clients.claim(); +}); + +self.addEventListener('fetch', (event) => { + if (event.request.method !== 'GET') return; + + event.respondWith( + caches.match(event.request).then((cached) => { + if (cached) return cached; + return fetch(event.request) + .then((response) => { + const shouldCache = + response && response.status === 200 && response.type === 'basic' && event.request.url.startsWith(self.location.origin); + if (shouldCache) { + const clone = response.clone(); + caches.open(CACHE_NAME).then((cache) => cache.put(event.request, clone)); + } + return response; + }) + .catch(() => { + if (event.request.mode === 'navigate') { + return caches.match('./'); + } + }); + }) + ); +});