-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbackground.html
47 lines (43 loc) · 1.68 KB
/
background.html
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
<html>
<head>
<script src="js/socket.io.js"></script>
<script>
function socketIOConnection() {
var value = localStorage["urlApp"];
var socket;
if (null != value) {
if (null != socket) {
alert('disconnect');
socket.disconnect();
socket = null;
}
socket = io.connect(localStorage["urlApp"], {transports: ['xhr-polling']});
var countOld = 0;
chrome.browserAction.setBadgeText({text:"?"});
socket.on('connect', function() {
chrome.browserAction.setBadgeText({text:"..."});
});
socket.on('status', function (status) {
var count = (status.summarize.critical + status.summarize.down + status.summarize.unknown).toString();
chrome.browserAction.setBadgeText({text:count});
if (window.webkitNotifications.checkPermission() == 0) {
if (countOld != count) {
var msg = 'Up: ' + status.summarize.up + ', ' + 'Critical: ' + status.summarize.critical + ', Down: ' + status.summarize.down + ', Unknown: ' + status.summarize.unknown;
var notification = webkitNotifications.createNotification('images/default_icon_128.png', 'Service problems', msg);
notification.show();
setTimeout(function() { notification.cancel(); }, 3000);
countOld = count;
}
} else {
window.webkitNotifications.requestPermission();
}
});
} else {
chrome.browserAction.setBadgeText({text:"url?"});
}
}
</script>
</head>
<body onload="socketIOConnection()">
</body>
</html>