You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pages/app.js

48 lines
858 B
JavaScript

function e(tag, attrs, content) {
const el = document.createElement(tag)
el.innerText = content
return el
}
3 years ago
class Setup {
constructor() {
this.loaded = false
}
async run() {
navigator.serviceWorker
.addEventListener('controllerchange', () => {
if (this.registration.active) {
this.loadIfReady()
}
})
await this.register()
this.loadIfReady()
}
3 years ago
async register() {
try {
this.registration =
await navigator.serviceWorker.register(
'/sw.js',
{scope: '/'}
)
} catch (err) {
console.error(
'error registering service worker', err
)
3 years ago
}
}
loadIfReady() {
if (
!this.loaded && this.registration.active
) {
document.body.appendChild(
e('h1', {}, location.hash)
)
}
}
3 years ago
}
new Setup().run()