-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.js
61 lines (53 loc) · 1.56 KB
/
main.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
55
56
57
58
59
60
61
function NotifyHatena() {
var self = this;
self.refresh();
window.setInterval(function() { self.refresh(); }, self._refreshTimeout);
}
NotifyHatena.prototype = {
_offLine: false,
_refreshTimeout: 60*1000*15, // 15 minutes
_feedUrl: 'https://www.hatena.ne.jp/notify/notices.count.json',
_setOffline: function() {
this._offLine = true;
kango.ui.browserButton.setTooltipText("未ログイン");
kango.ui.browserButton.setIcon('icons/icon32_gray.png');
kango.ui.browserButton.setBadgeValue(0);
},
_setUnreadCount: function(count) {
kango.ui.browserButton.setTooltipText("未読数: " + count);
kango.ui.browserButton.setIcon('icons/icon32.png');
kango.ui.browserButton.setBadgeValue(count);
},
isLogin: function(){
return (this._offLine != false);
},
clean: function() {
var self = this;
self._setUnreadCount(0);
},
refresh: function() {
var details = {
url: this._feedUrl,
method: 'GET',
async: true,
contentType: 'text'
};
var self = this;
kango.xhr.send(details, function(data) {
if(data.status == 200 && data.response != null) {
self._offLine = false;
var notify = JSON.parse(data.response);
self._setUnreadCount(notify['count']);
}
else {
self._setOffline();
}
});
}
};
var notifyHatena;
kango.ui.addEventListener(kango.ui.event.Ready, function() {
if(notifyHatena == undefined)
notifyHatena = new NotifyHatena();
return notifyHatena;
});