-
Notifications
You must be signed in to change notification settings - Fork 88
/
test1.html
110 lines (91 loc) · 2.19 KB
/
test1.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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<!doctype html>
<html>
<head>
<title>JSONAPI websocket test</title>
<script type="text/javascript" src="../jsonapi-v2.js"></script>
<style>
body {
background:black;
font:13px monospace;
color:white;
padding:5px 5px 45px 5px;
margin:0;
}
ul, ul li, li {
margin:0;
padding:0;
}
#input {
position:fixed;
bottom:0;
left:0;
right:0;
background:white;
padding:5px;
}
input {
margin:0;
padding:5px;
width:83%;
}
button {
width:9%;
margin-left:5%;
}
.color-33 {color:gold;}
.color-35 {color:purple;}
.color-37 {color:gray;}
.color-31 {color:red;}
</style>
</head>
<body>
<ul name="console" id="console"></ul>
<div id="input"><input type="text" id="inp" /><button id="run">Send</button></div>
<script type="text/javascript">
var j = new JSONAPI({
hostname: "localhost",
port: 20059,
username: "usernameGoesHere",
password: "passwordGoesHere",
salt: "salt goes here"
})
, $ = function(x) { return document.getElementById(x); }
, c = $('console')
;
j.stream('console', function(json) {
appendLine(json.success.line);
});
function send () {
var txt = $('inp').value;
if(!txt.length) return;
j.call('runConsoleCommand', txt);
appendLine("> " + txt + "\r\n");
}
function appendLine (txt) {
var el = document.createElement('li');
el.innerHTML = colorize(escape_html(txt));
c.appendChild(el);
document.body.scrollTop = document.body.scrollHeight;
}
$('run').addEventListener('click', send);
$('inp').addEventListener('keydown', function(e) {
if(e.which == 13) {
send();
e.target.value = "";
}
});
$('inp').focus();
function escape_html(string) {
return (''+string).replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"').replace(/'/g, ''').replace(/\//g,'/');
}
function colorize(str) {
var i = 0;
return str.replace(/(\[([0-9]{1,2})m)/g, function() {
var txt = (i ? '</span>' : '') + '<span class="color-' + arguments[2] + '">';
i++;
return txt;
}) + (i?'</span>':'');
}
</script>
</body>
</html>