-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.html
57 lines (57 loc) · 1.54 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
<!DOCTYPE html>
<html>
<head>
<title>Webtail</title>
<script src="https://cdn.bootcss.com/jquery/2.2.2/jquery.min.js"></script>
<style>
pre.line {
margin: 0;
padding: 0;
}
</style>
</head>
<body>
<div id="fileData"></div>
<script type="text/javascript">
function getId(){
var queryString = location.search.replace('?', '')
if(!queryString){
return ''
}
var arr = queryString.split('&')
for(var i = 0 ; i < arr.length; i++){
if(arr[i].indexOf('id=') === 0){
return decodeURIComponent(arr[i].replace('id=', ''))
}
}
return ''
}
(function() {
var data = $("#fileData");
function onclose(evt) {
console.log('close ed')
data.text('Connection closed');
// retry
// conn = new WebSocket("ws://localhost:3000/ws?id=" + getId());
data.empty();
conn.onclose = onclose;
conn.onmessage = onmessage;
};
function onmessage(evt) {
console.log('file updated');
if (evt.data == "\n") {
data.append("<pre class='blank'>"+evt.data+"</pre>");
} else {
data.append("<pre class='line'>"+evt.data+"</pre>");
}
};
var conn = new WebSocket("ws://localhost:3000/ws?id=" + getId());
conn.onclose = onclose
conn.onmessage = onmessage
$("#fileName").change(function () {
conn.close()
});
})();
</script>
</body>
</html>