home-app/src/main.ts

63 lines
1.8 KiB
TypeScript
Raw Normal View History

2022-05-01 06:04:07 +00:00
const APP_VERSION = __APP_VERSION__;
const APP_BUILD_TIME = __APP_BUILD_TIME__;
2022-04-29 15:32:11 +00:00
2022-04-30 03:45:14 +00:00
import "./styles.css";
2022-04-29 14:52:00 +00:00
import Typed from "typed.js";
2022-05-01 06:04:07 +00:00
import Tippy from 'tippy.js';
import 'tippy.js/dist/tippy.css';
import 'tippy.js/animations/scale.css';
2022-04-29 15:32:11 +00:00
window.addEventListener("load", (_ev) => {
2022-04-30 13:12:41 +00:00
new Typed(document.querySelector("description") ?? "description", {
stringsElement: "#description-list",
shuffle: true,
typeSpeed: 60,
backDelay: 2000,
fadeOut: true,
loop: true,
showCursor: true,
smartBackspace: true,
});
2022-04-29 14:52:00 +00:00
2022-04-30 13:12:41 +00:00
document.querySelectorAll("[alt]").forEach((Elem) => {
2022-05-01 06:04:07 +00:00
Tippy(Elem, {
content: Elem.getAttribute("alt") ?? "",
})
2022-04-30 13:12:41 +00:00
});
2022-04-29 15:32:11 +00:00
2022-04-30 13:12:41 +00:00
// @ts-expect-error
document.querySelector(
"#footer > div"
2022-05-01 06:04:07 +00:00
).innerHTML += `<a href="https://git.186526.xyz/186526/home-app"><img alt="Update Commit" src="https://blog.186526.xyz/shields.io/badge/commit-${APP_VERSION}-blue" /></a> <img alt="Latest Update" src="https://blog.186526.xyz/shields.io/date/${APP_BUILD_TIME}?color=sucessful&label=latest%20update" />`;
// @ts-expect-error
document.querySelector("#footer").innerHTML = document.querySelector("#footer")?.innerHTML.replaceAll("unknown",__APP_BUILD_MACHINE__);
2022-04-29 15:32:11 +00:00
2022-04-30 13:12:41 +00:00
if ("serviceWorker" in navigator) {
navigator.serviceWorker
.register("./sw.js", {
scope: "/",
})
.then(function (registration) {
console.log(
"ServiceWorker registration successful with scope: ",
registration.scope
);
})
.catch(function (err) {
console.warn("ServiceWorker registration failed: ", err);
});
let refreshing = false;
navigator.serviceWorker.addEventListener("controllerchange", () => {
if (refreshing) {
return;
}
refreshing = true;
window.location.reload();
});
}
2022-04-29 14:52:00 +00:00
});