blob: 8f2f7be6bfa7e440a01ec8083d1917bc676ed134 (
plain)
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
|
<meta charset="UTF-8">
<body onload="getNotPerm()">
<!--- Import jquery-->
<script src="jquery-3.3.1.min.js"></script>
<script>
//function called after permission has been requested
function handlePermissions(result) {
console.log("Permission "+ result);
permissionDisplay = document.getElementsByClassName("pd")[0];
grantedMsg = "You have granted notification permissions";
deniedMsg = "You have not granted notification permissions";
//updates permissions
if(result == "granted"){
permissionDisplay.innerHTML = grantedMsg;
} else {
permissionDisplay.innerHTML = deniedMsg;
}
return;
}
//gets notification permissions
function getNotPerm() {
//makes handlePermissions() the callback
Notification.requestPermission().then(handlePermissions);
//requests permissions
Notification.requestPermission();
return;
}
//sends a new message
function notify() {
msg = new Notification("あなたはチンチンが大好き");
}
//performing an https POST on the backend
$.post("https://" + window.hostname.location + "/api/msg",
{last-displayed: 0},// data to submit
function(data, status, jqXHR) { //callback function
if (data == ""){
return;
}
console.log(data);
}
}
</script>
<!--- Permission display-->
<p class="pd">You have not granted notification permissions</p>
<button onclick="getNotPerm()">Re-request Notification Permissions</button>
<button onclick="notify()">Send Notifications</button>
</body>
|