forked from bhelx/live-file
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
91 lines (86 loc) · 3.17 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
<!DOCTYPE html>
<html>
<head>
<title>Live-File</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="/socket.io/socket.io.js"></script>
<style type="text/css" rel="stylesheet">
body{background-color:#222;}
#info{ font-size: 32px; color:#FFFFFF;text-shadow:#444 1px 1px 2px; text-align:right;margin:20px 10px;text-transform:lowercase;}
#tail{ border: 1px solid #444; overflow-x:hidden; overflow-y:auto; background-color:#333; color: #EEE; text-shadow:#000 0 0 2px; height: 500px; padding: 10px; font-size:12px; line-height:20px;}
.trebuchet{font-family: "Trebuchet MS","Lucida Sans Unicode","Lucida Grande","Lucida Sans",Arial,sans-serif;}
.monospace{font-family: Monaco,"Bitstream Vera Sans Mono","Lucida Console",Terminal,monospace;}
.selection::selection , .selection *::selection{background: #EEE;color:#000;border-color:#000; text-shadow:#fff 0 0 2px;}
.selection::-moz-selection , .selection *::-moz-selection{background: #EEE;color:#000;border-color:#000; text-shadow:#fff 0 0 2px;}
</style>
</head>
<body>
<div id="info" class="trebuchet"></div>
<div id="backlog" class="monospace selection"></div>
<div id="tail" class="monospace selection"></div>
<script type="text/javascript">
(function() {
var scrollLocked = true;
var preventScroll = false;
var scrollPosition = 0;
var $tail = $('#tail');
var topByte = -1;
function tailHitTop() {
return scrollPosition == 0;
}
function tailHitBottom() {
return $tail.height() + scrollPosition == $tail.attr("scrollHeight") - 20;
}
function onScroll(cb) {
var didScroll = false;
$tail.scroll(function () { didScroll = true; });
setInterval(function () {
if (didScroll) {
didScroll = false;
cb();
}
}, 250);
}
onScroll(function () {
scrollPosition = $tail.scrollTop();
if (tailHitBottom()) {
scrollLocked = true;
} else {
scrollLocked = false;
if (tailHitTop() && topByte > 0) {
$.getJSON('/', {pivot: topByte}, function (data) {
var rand = Math.floor(Math.random()*999999999);
$tail.prepend(data.tail.join('<br />') + '<span id="span'+rand+'">');
topByte = data.topByte;
$tail.scrollTop($("#span"+rand).offset().top);
console.log(data);
});
}
}
});
var lines = 0, notice = $("#info"), buffer = $tail;
var socket = io.connect("/");
socket.on('connect', function () {
console.log('Connected to:', socket.host);
});
socket.on('message', function (message) {
console.log('Received message:', message);
if (message.topByte) {
topByte = message.topByte;
}
if (message.tail) {
buffer.append(message.tail.join('<br/>'));
lines = lines + message.tail.length;
if (scrollLocked) {
$('#tail').scrollTop($('#tail').attr("scrollHeight"));
}
}
if (message.filename) {
notice.html(message.filename);
}
});
})();
</script>
</body>
</html>