-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstall.js
More file actions
73 lines (46 loc) · 1.29 KB
/
Copy pathinstall.js
File metadata and controls
73 lines (46 loc) · 1.29 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
let deferredPrompt=null;
const installButton=document.createElement("button");
installButton.id="install-app";
installButton.innerHTML="📲 Install App";
installButton.style.cssText=`
position:fixed;
right:20px;
bottom:20px;
z-index:99999;
padding:14px 22px;
border:none;
outline:none;
border-radius:50px;
background:linear-gradient(135deg,#2563eb,#38bdf8);
color:#fff;
font-size:16px;
font-weight:600;
cursor:pointer;
display:none;
box-shadow:0 10px 35px rgba(37,99,235,.45);
transition:.35s;
`;
document.body.appendChild(installButton);
installButton.onmouseenter=()=>installButton.style.transform="translateY(-3px) scale(1.03)";
installButton.onmouseleave=()=>installButton.style.transform="translateY(0) scale(1)";
window.addEventListener("beforeinstallprompt",e=>{
e.preventDefault();
deferredPrompt=e;
installButton.style.display="block";
});
installButton.addEventListener("click",async()=>{
if(!deferredPrompt)return;
deferredPrompt.prompt();
const result=await deferredPrompt.userChoice;
if(result.outcome==="accepted"){
console.log("PWA Installed");
}else{
console.log("Installation Cancelled");
}
deferredPrompt=null;
installButton.style.display="none";
});
window.addEventListener("appinstalled",()=>{
console.log("Application Installed Successfully");
installButton.remove();
});