-
Notifications
You must be signed in to change notification settings - Fork 0
/
_notif.js
46 lines (46 loc) · 1.68 KB
/
_notif.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
var _notif = {
internalVar: [],
vars: function(name, value){
if(name===undefined){
if(typeof localStorage!=='undefined') return localStorage;
else return _notif.internalVar;
}else{
if(value===undefined){
if(typeof localStorage!=='undefined') return localStorage.getItem(name);
else if(_notif.internalVar[name]!==undefined) return _notif.internalVar[name];
else return null;
}else{
if(typeof localStorage!=='undefined') return localStorage.setItem(name, value);
else _notif.internalVar[name] = value;
}
}
},
show: function(params){
if(!("Notification" in window)) return;
var title, name;
if(typeof params === 'object') title = params.title;
else{
title = params;
params = {};
}
if(params.name===undefined) name = title;
else name = params.name;
if(params.counter!==undefined){
if(_notif.vars('_notify_Last_' + name)===null) _notif.vars('_notify_Last_' + name, 0);
if(_notif.vars('_notify_' + name)===null) _notif.vars('_notify_' + name, 0);
if(_notif.vars('_notify_Last_' + name)==params.counter) return;
_notif.vars('_notify_Last_' + name, params.counter);
if(_notif.vars('_notify_' + name)<params.counter){
localStorage.setItem('_notify_' + name, params.counter);
}else if(_notif.vars('_notify_' + name)>params.counter){
_notif.vars('_notify_Last_' + name, params.counter);
_notif.vars('_notify_' + name, params.counter);
return;
}
}
if(Notification.permission === "granted"){
var notification = new Notification(title, params);
notification.onclick = function(){ window.focus(); this.close(); };
}else Notification.requestPermission();
}
};