-
Notifications
You must be signed in to change notification settings - Fork 1
/
getNotification.js
54 lines (48 loc) · 1.45 KB
/
getNotification.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
43
44
45
46
47
48
49
50
51
52
53
54
var notifID = undefined;
function setNotification() {
requestPermission();
if (notifID !== undefined) {
clearInterval(notifID);
}
$.post("getNotification.php", {ownerId: getCookie("ownerId"),
password: getCookie("password")}, function(data){
if(data !== "No plan"){
var nextDuePlan = JSON.parse(data);
callNotification(nextDuePlan.name, nextDuePlan.due, nextDuePlan.reminder);
}
});
}
function callNotification(name, due, reminder) {
var notificationTime = Date.parse(reminder);
var current = new Date();
var diff = notificationTime - current.getTime();
notifID = setInterval(function(){
current = new Date();
diff = notificationTime - current.getTime();
if (diff <= 0) {
showNotificatioin("Reminder: " + name, "Due: " + due);
music();
clearInterval(notifID);
setNotification();
}
}, 60000);
}
var audio = $("#audio")[0];
function music() {
audio.play();
setTimeout("audio.pause()", 5000);
}
function requestPermission(){
if (Notification) {
Notification.requestPermission();
}
}
function showNotificatioin(title, body){
var options = {body: body, icon: "Images/AntPlannerIcon.png", tag: "dueNotification"};
if (Notification) {
requestPermission();
if (Notification.permission === "granted") {
notify = new Notification(title, options);
}
}
}