This commit is contained in:
marlon-erler
2024-07-07 16:56:12 +02:00
parent 9dd55f650b
commit b047f1b5e8
7 changed files with 78 additions and 3 deletions
+21
View File
@@ -1,3 +1,4 @@
// TABS
document.querySelector("main").addEventListener("scroll", () => {
const links = document.querySelectorAll(".tab-link");
links.forEach((element) => element.removeAttribute("active"));
@@ -8,3 +9,23 @@ document.querySelector("main").addEventListener("scroll", () => {
if (links[currentPage]) links[currentPage].setAttribute("active", "");
});
// SERVICE WORKER
async function registerServiceWorker() {
if ("serviceWorker" in navigator) {
try {
const registration = await navigator.serviceWorker.register("/sw.js", {
scope: "/",
});
if (registration.installing) {
setTimeout(() => window.location.reload(), 500);
} else if (registration.active) {
console.log("Service worker active");
}
} catch (error) {
console.error(`Could not install service worker: ${error}`);
}
}
}
registerServiceWorker();