diff --git a/elevators.js b/elevators.js index 068a1b3..309ad56 100644 --- a/elevators.js +++ b/elevators.js @@ -6,11 +6,6 @@ let geolocationPermission = false; let geolocation = null; const openStations = new Set(); let sortByDistance = false; -const version = '0.5.2' -const minorVersion = version.split('.').splice(0, 2).join('.'); -const numberFormat = new Intl.NumberFormat('de-DE', { - maximumFractionDigits: 1 -}); const substituteData = [ { @@ -87,14 +82,6 @@ const substituteData = [ }, ] - -Object.defineProperty(String.prototype, 'capitalize', { - value: function () { - return this.charAt(0).toUpperCase() + this.toLowerCase().slice(1); - }, - enumerable: false -}); - async function loadElevators() { document.querySelector('#errorMessage').classList.add('hidden'); const res = await fetch('https://www.hvv.de/elevators', { @@ -203,12 +190,6 @@ async function loadElevators() { })); } -const dateTimeStyle = new Intl.DateTimeFormat('de-DE', { - dateStyle: 'medium', - timeStyle: 'medium', - timeZone: 'Europe/Berlin', -}) - async function loadOsmData() { const nodeIdList = []; for (const station of internalData.stations) { @@ -726,21 +707,6 @@ document.querySelectorAll('button.typeChip').forEach(e => { }) }) -function openDialog(selector) { - document.querySelector('body').classList.add('has-dialog') - document.querySelector('#dialog_layer').classList.add('active') - document.querySelector(selector).classList.remove('hidden') -} - -function closeDialog(selector) { - document.querySelector('body').classList.remove('has-dialog') - document.querySelector('#dialog_layer').classList.remove('active') - document.querySelector(selector).classList.add('hidden') -} - -// set version -document.querySelector('#version').innerHTML = `v${version}`; - // data api version check const check_internal = JSON.parse(localStorage.getItem("internal_data")); const check_osm = JSON.parse(localStorage.getItem("osm_data")); diff --git a/icons/192.png b/icons/192.png new file mode 100644 index 0000000..cefddc9 Binary files /dev/null and b/icons/192.png differ diff --git a/icons/512-maskable.png b/icons/512-maskable.png new file mode 100644 index 0000000..7cc4bf2 Binary files /dev/null and b/icons/512-maskable.png differ diff --git a/icons/512-transparent.png b/icons/512-transparent.png new file mode 100644 index 0000000..4ca9254 Binary files /dev/null and b/icons/512-transparent.png differ diff --git a/icons/512.png b/icons/512.png new file mode 100644 index 0000000..fc7c100 Binary files /dev/null and b/icons/512.png differ diff --git a/icons/favicon-maskable.svg b/icons/favicon-maskable.svg new file mode 100644 index 0000000..922562d --- /dev/null +++ b/icons/favicon-maskable.svg @@ -0,0 +1,24 @@ + + + + diff --git a/icons/favicon-transparent.svg b/icons/favicon-transparent.svg new file mode 100644 index 0000000..c0f192e --- /dev/null +++ b/icons/favicon-transparent.svg @@ -0,0 +1,18 @@ + + + + diff --git a/icons/favicon.ico b/icons/favicon.ico new file mode 100644 index 0000000..29e9f5e Binary files /dev/null and b/icons/favicon.ico differ diff --git a/icons/favicon.svg b/icons/favicon.svg new file mode 100644 index 0000000..6c0a019 --- /dev/null +++ b/icons/favicon.svg @@ -0,0 +1,23 @@ + + + + diff --git a/images/screenshot-desktop.png b/images/screenshot-desktop.png new file mode 100644 index 0000000..4856c04 Binary files /dev/null and b/images/screenshot-desktop.png differ diff --git a/images/screenshot-mobile.png b/images/screenshot-mobile.png new file mode 100644 index 0000000..2856686 Binary files /dev/null and b/images/screenshot-mobile.png differ diff --git a/index.html b/index.html index 4af499c..863abc6 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,11 @@ content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0"> + + + + + Barrierefreie Aufzugs-Liste @@ -88,6 +93,7 @@ + \ No newline at end of file diff --git a/main.js b/main.js new file mode 100644 index 0000000..a861c00 --- /dev/null +++ b/main.js @@ -0,0 +1,41 @@ +const version = '0.6.0' +const minorVersion = version.split('.').splice(0, 2).join('.'); +const numberFormat = new Intl.NumberFormat('de-DE', { + maximumFractionDigits: 1 +}); + +Object.defineProperty(String.prototype, 'capitalize', { + value: function () { + return this.charAt(0).toUpperCase() + this.toLowerCase().slice(1); + }, + enumerable: false +}); + +const dateTimeStyle = new Intl.DateTimeFormat('de-DE', { + dateStyle: 'medium', + timeStyle: 'medium', + timeZone: 'Europe/Berlin', +}) + +// set version +document.querySelector('#version').innerHTML = `v${version}`; + + +function openDialog(selector) { + document.querySelector('body').classList.add('has-dialog') + document.querySelector('#dialog_layer').classList.add('active') + document.querySelector(selector).classList.remove('hidden') +} + +function closeDialog(selector) { + document.querySelector('body').classList.remove('has-dialog') + document.querySelector('#dialog_layer').classList.remove('active') + document.querySelector(selector).classList.add('hidden') +} + +if ("serviceWorker" in navigator) { + console.log('installing sw'); + navigator.serviceWorker.register("/sw.js").then((registration) => { + console.log('done installing sw'); + }); +} diff --git a/manifest.json b/manifest.json new file mode 100644 index 0000000..77dfd27 --- /dev/null +++ b/manifest.json @@ -0,0 +1,49 @@ +{ + "name": "hvvstuhl.de", + "short_name": "hvvstuhl", + "start_url": ".", + "display": "standalone", + "background_color": "#030712", + "theme_color": "#047857", + "description": "Barrierefreie Aufzugs-Liste", + "icons": [ + { + "src": "/icons/192.png", + "sizes": "192x192", + "type": "image/png" + }, + { + "src": "/icons/512.png", + "sizes": "512x512", + "type": "image/png" + }, + { + "src": "/icons/512-maskable.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "maskable" + }, + { + "src": "/icons/512-transparent.png", + "sizes": "512x512", + "type": "image/png", + "purpose": "monochrome" + } + ], + "screenshots" : [ + { + "src": "images/screenshot-mobile.png", + "sizes": "430x900", + "type": "image/png", + "form_factor": "narrow", + "label": "Stationsliste" + }, + { + "src": "images/screenshot-desktop.png", + "sizes": "1280x720", + "type": "image/png", + "form_factor": "wide", + "label": "Stationsliste" + } + ] +} diff --git a/sw.js b/sw.js new file mode 100644 index 0000000..335ca35 --- /dev/null +++ b/sw.js @@ -0,0 +1,96 @@ +const version = '0.6.0' +const consolePrefix = `[SW v${version}] ` + +const cacheName = `hvvstuhl-${version}`; +const contentToCache = [ + '/', + '/index.html', + '/about.html', + '/main.js', + '/elevators.js', + '/style.css', + '/icons/192.png', + '/icons/512.png', + '/icons/512-maskable.png', + '/icons/512-transparent.png', + '/icons/favicon.ico', + '/icons/favicon.svg', + '/icons/favicon-maskable.svg', + '/icons/favicon-transparent.svg', + '/md_icons/bicycle.svg', + '/md_icons/braille.svg', + '/md_icons/door_sliding.svg', + '/md_icons/elevator.svg', + '/md_icons/elevator-slash.svg', + '/md_icons/fit_width.svg', + '/md_icons/height.svg', + '/md_icons/info.svg', + '/md_icons/load.svg', + '/md_icons/location.svg', + '/md_icons/location-searching.svg', + '/md_icons/speaker.svg', + '/md_icons/up-down.svg', + '/md_icons/wheelchair.svg', + '/md_icons/width.svg', +]; + +// Service worker Install: Cache all files +self.addEventListener("install", (e) => { + console.log("[Service Worker] Wird installiert...."); + e.waitUntil( + (async () => { + const cache = await caches.open(cacheName); + console.log("[Service Worker] Cache wird aufgebaut..."); + await cache.addAll(contentToCache); + console.log("[Service Worker] FERTIG"); + })(), + ); +}); + + +// delete old caches +const deleteCache = async (key) => { + await caches.delete(key); +}; +const deleteOldCaches = async () => { + const keyList = await caches.keys(); + const cachesToDelete = keyList.filter((key) => key !== cacheName); + await Promise.all(cachesToDelete.map(deleteCache)); +}; +self.addEventListener("activate", (event) => { + event.waitUntil( + (async () => { + await deleteOldCaches() + await clients.claim(); + })(), + ); +}); + + + +// Respond with data from cache when offline +self.addEventListener("fetch", (e) => { + e.respondWith( + (async () => { + const path = new URL(e.request.url).pathname + + if(contentToCache.includes(path)){ + console.log(`${consolePrefix}Anfrage: ${path}`); + + const r = await caches.match(e.request); + if (r) { + console.log(`${consolePrefix} Im Cache gefunden.`); + return r; + } + const response = await fetch(e.request); + const cache = await caches.open(cacheName); + console.log(`${consolePrefix} Nicht gefunden. Aktualisiere Cache: ${path}`); + await cache.put(e.request, response.clone()); + return response; + }else{ + console.log(`${consolePrefix}Anfrage übersprungen: ${e.request.url}`); + return await fetch(e.request); + } + })(), + ); +}); \ No newline at end of file