-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
94 lines (77 loc) · 2.2 KB
/
index.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
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
<html>
<head>
<title>node log stream</title>
<style type="text/css">
body {
padding: 0;
margin: 0;
font-family: Helvetica, Tahoma, fixed;
font-size: 12pt;
line-height: 120%;
color: #0f0;
background: #000;
}
#log {
display: block;
overflow: hidden;
}
.logLine {
border-bottom: 1px dotted #aaa;
padding: 8px 0px 8px 0px;
margin-bottom: 8px;
}
</style>
<link rel="icon" type="image/vnd.microsoft.icon" href="favicon.ico" />
<script src="jquery-1.2.6.min.js" type="text/javascript"></script>
</head>
<body>
<div id="app">
<div id="log"></div>
</div>
<script type="text/javascript">
g = { hasFocus : true, unreadCount : 0 };
function scrollDown () { window.scrollBy(0, 100000000000000000); }
function addLine (data) {
if ((data === null) || (data && !data.lines) || (data && data.lines && (data.lines.length < 1)))
return;
for (var i = 0; (i < data.lines.length); i++) {
var logLineContainer = $(document.createElement("div"));
var content = '<div class="logLine">' + data.lines[i] + '</div>';
logLineContainer.html(content);
$("#log").append(logLineContainer);
}
if (!g.hasFocus) {
g.unreadCount++;
document.title = "(" + g.unreadCount + ") node log stream";
}
scrollDown();
}
function longPoll (data) {
if (data && data.data && data.data.lines) {
addLine(data.data);
}
$.ajax({ cache: false , type: "GET" , url: "/recv" , dataType: "json",
data: { d : null },
error: function () {
longPoll();
},
success: function (data) {
longPoll(data);
}
});
}
$(window).load(function() {
longPoll();
});
$(window).blur(function() {
g.hasFocus = false;
g.unreadCount = 0;
});
$(window).focus(function() {
g.hasFocus = true;
g.unreadCount = 0;
document.title = "node log stream";
});
</script>
</body>
</html>