forked from awmorp/turing
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.js
32 lines (28 loc) · 952 Bytes
/
notify.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
/*
* Fonction javascript basique pour envoyer une notification
* Par Lilian Besson - https://github.com/Naereen/jsTuring_fr
*/
var notificationEvents = ['onclick', 'onshow', 'onerror', 'onclose'];
function notifyUser(body) {
if ('Notification' in window) {
var title;
var options;
title = "Simulateur de Machines de Turing";
options = {
body: body,
tag: 'preset',
icon: 'favicon.png'
};
Notification.requestPermission(function() {
var notification = new Notification(title, options);
notificationEvents.forEach(function(eventName) {
notification[eventName] = function(event) {
console.log("WebNotification-API: notification sent, with title ='", title, "' and body ='", body, "' ...");
};
});
});
}
else {
console.log("WebNotification-API: API not available... body ='", body, "'...");
}
}