-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
42 lines (37 loc) · 1.13 KB
/
script.js
File metadata and controls
42 lines (37 loc) · 1.13 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
const button = document.querySelector("button");
button.addEventListener("click", () => {
// alert("hi");
Notification.requestPermission().then((permission) => {
if (permission === "granted") {
const notification = new Notification("Sample Javascript Notification", {
body: Math.random(),
tag: "Test Unique Tag",
icon: "./bell.png",
});
}
// notification.addEventListener("error", (e) => {});
});
});
// let outsideNotification;
// let interval;
// document.addEventListener("visibilitychange", () => {
// if (document.visibilityState === "hidden") {
// console.log("hidden");
// let goneDate = new Date();
// interval = setInterval(() => {
// outsideNotification = new Notification("Please come back ! ", {
// body: `You have been gone for
// ${Math.round((new Date() - goneDate) / 1000)} seconds`,
// tag: "Left the Page Tag",
// // icon: "./bell.png",
// });
// }, 100);
// } else {
// if (interval) {
// clearInterval();
// }
// if (outsideNotification) {
// outsideNotification.close();
// }
// }
// });