-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathscriptss.js
31 lines (31 loc) · 1.13 KB
/
scriptss.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
const button = document.querySelector('button');
button.addEventListener('click', function() {
Notification.requestPermission().then(perm=>{
if(perm==="granted"){
const notify=new Notification("Item Added",{
body:"Congrats!🎉🎉",
data:{ Say:"yo boy kongming"},
icon:"logoimg.png",
tag:"test"
})
notify.addEventListener("close",e=>{
console.log(e)
})
let note
let interval
document.addEventListener("visibilitychange",()=>{
if(document.visibilityState==="hidden"){
const leaveDate=new Date();
interval=setInterval(()=>{
note= new Notification("Please Come Back😢😢",{
body:`You are ${Math.round((new Date()-leaveDate)/1000)} seconds late😈`
})
},4000)
}else{
if(interval)clearInterval(interval)
if(note)Notification.close()
}
})
}
})
})