-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathindex.js
36 lines (28 loc) · 947 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
;(function () {
if ('serviceWorker' in navigator) {
return installServiceWorker()
}
function offlineNotAvaiable() {
document.getElementsByTagName('h1')[0].textContent = 'Service Worker Not Available'
}
function installServiceWorker() {
navigator.serviceWorker.register('./service-worker.js')
navigator.serviceWorker.oncontrollerchange = onControllerChange
}
function onControllerChange() {
var html = '<div style="'
html += 'position: fixed; bottom: 1em; left: 1em;'
if (localStorage.getItem('service-worker')) {
html += 'background: yellow; padding: 1em;'
html += '">'
html += 'Refresh the page to see the newest content'
} else {
html += 'background: green; padding: 1em;'
html += '">'
html += 'Offline Ready'
localStorage.setItem('service-worker', 'done')
}
html += '</div>'
document.body.insertAdjacentHTML('beforeend', html)
}
}())