-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
17 lines (16 loc) · 918 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
if ('serviceWorker' in navigator) {
window.addEventListener('load', function() {
navigator.serviceWorker.register('sw.js').then(function(registration) {
// Registration was successful
console.log('ServiceWorker registration successful with scope: ', registration.scope);
}, function(err) {
// registration failed :(
console.log('ServiceWorker registration failed: ', err);
});
});
}
var deferredPrompt;
function a2hs(){
btnAdd.style.display="none",deferredPrompt.prompt(),deferredPrompt.userChoice.then(e=>{"accepted"===e.outcome?console.log("User accepted the A2HS prompt"):console.log("User dismissed the A2HS prompt"),deferredPrompt=null})
}
window.addEventListener("beforeinstallprompt",e=>{console.log("beforeinstallprompt"),e.preventDefault(),deferredPrompt=e,btnAdd.style.display="block"}),window.addEventListener("appinstalled",e=>{console.log("a2hs","installed")});