-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.js
42 lines (38 loc) · 1.24 KB
/
script.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
32
33
34
35
36
37
38
39
40
41
42
document.addEventListener('DOMContentLoaded', () => {
const button = document.getElementById("push_token_btn");
button.addEventListener("click", async () => {
const token = document.getElementById("push_token").value;
const server = document.getElementById("server_url").value;
if (token && server) {
createNotify("Connecting...", {
body: "Connect to " + server,
icon: "images/icon.png",
data: "https://im.dengzii.com/"
});
}
})
})
function createNotify(title, options) {
if (Notification.permission === "granted") {
notify(title, options);
} else {
Notification.requestPermission(function (res) {
if (res === "granted") {
notify(title, options);
}
}).then(r => {
console.log(r);
});
}
function notify($title, $options) {
const notification = new Notification($title, $options);
notification.onshow = function (event) {
};
notification.onclose = function (event) {
};
notification.onclick = function (event) {
window.open(event.target.data)
notification.close();
};
}
}