Files
desfoto/site/gtin/js/aktualisieren.js
2026-09-25 20:08:25 +02:00

34 lines
1.1 KiB
JavaScript

/* Entfernt die umgeleitete Startantwort aus frueheren GTIN-Caches. */
const status = document.querySelector('#status');
const appUrl = new URL('../', window.location.href);
const alterIndex = new URL('index.html', appUrl).href;
async function aktualisiereWerkzeug() {
if ('caches' in window) {
const namen = await caches.keys();
for (const name of namen) {
if (!name.startsWith('desfoto-gtin-generator-')) continue;
const cache = await caches.open(name);
const antwort = await cache.match(alterIndex);
if (antwort?.redirected) await cache.delete(alterIndex);
}
}
if ('serviceWorker' in navigator) {
const registrierung = await navigator.serviceWorker.getRegistration(appUrl.href);
if (registrierung) {
await Promise.race([
registrierung.update().catch(() => undefined),
new Promise((resolve) => window.setTimeout(resolve, 5000)),
]);
}
}
window.location.replace(appUrl.href);
}
aktualisiereWerkzeug().catch(() => {
status.textContent = 'Die Aktualisierung ist fehlgeschlagen. Bitte lösche die Website-Daten für desfoto.de in deinem Browser und öffne das Werkzeug erneut.';
});