-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
45 lines (41 loc) · 1.38 KB
/
index.html
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
<!DOCTYPE html>
<html lang="en-US" dir="ltr">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="shortcut icon" href="https://c.s-microsoft.com/favicon.ico?v2" />
<link rel="manifest" href="manifest.json" />
<title>Alco-Calc</title>
</head>
<body>
<button id="notifications">Receive Notification in 5 minute</button>
</body>
<script>
if ("serviceWorker" in navigator) {
navigator.serviceWorker.register("service-worker.js");
}
const button = document.getElementById("notifications");
button.addEventListener("click", async () => {
const statusP = await navigator.permissions.query({
name: "periodic-background-sync",
});
const statusN = await navigator.permissions.query({
name: "notifications",
});
if (statusP.state === "granted" && statusN.state === "granted") {
// Continue registering the periodic sync
return registerPeriodicNewsCheck();
}
});
async function registerPeriodicNewsCheck() {
const registration = await navigator.serviceWorker.ready;
try {
await registration.periodicSync.register("update-alco", {
minInterval: 2 * 60 * 1000,
});
} catch (error) {
console.log("Periodic Sync could not be registered!", error);
}
}
</script>
</html>