-
Notifications
You must be signed in to change notification settings - Fork 4
/
htmlws.htm
139 lines (125 loc) · 4.29 KB
/
htmlws.htm
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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style>
#txtContent{
width:100%;
}
#sendText{
width:100%;
}
#serverPath{
width:40%;
}
body{
background-color:#303030;
}
input{
background-color: #303030;
color:#00d4b1;
}
textarea{
background-color: #303030;
color: #00ca7d;
}
</style>
</head>
<body>
<h3 style="text-align:center;font-size:xx-large;color: #ffffff">WS测试</h3>
<div id="login">
<div>
<input id="serverIP" type="text" placeholder="服务器IP" value="127.0.0.1" autofocus="autofocus" />
<input id="serverPort" type="text" placeholder="服务器端口" value="41919" />
<input id="serverPath" type="text" placeholder="路径" value="/ws?token=" />
<input id="btnConnect" type="button" value="连接" onclick="connect()" />
</div>
<div>
<div style="color: #ffffff;">
命令执行情况
</div>
<textarea id="txtContent" readonly="readonly"></textarea>
</div>
<div>
<input id="sendText" type="text" placeholder="发送文本" value="" />
<input id="btnSend" type="button" value="发送" onclick="send()" />
<p id="wd" style="color:#00ca7d">你的工作路径:</p><a id="wda" target="__blank">here</a>
</div>
</div>
</body>
<script>
var socket;
function connect() {
var host = "ws://" + $("serverIP").value + ":" + $("serverPort").value + $("serverPath").value;
socket = new WebSocket(host);
try {
socket.onopen = function (msg) {
// $("btnConnect").disabled = true;
alert("连接成功!");
};
socket.onmessage = function (msg) {
if (typeof msg.data == "string") {
displayContent(msg.data);
}
else {
alert("非文本消息");
}
};
socket.onclose = function (msg) { alert("socket closed!") };
}
catch (ex) {
log(ex);
}
}
function send() {
var st=document.getElementById("sendText")
var msg = st.value;
st.value="";
//console.log(msg+String.fromCharCode(2,3,3));
socket.send(msg);
}
window.onbeforeunload = function () {
try {
socket.close();
socket = null;
}
catch (ex) {
}
};
function $(id) { return document.getElementById(id); }
function displayContent(msg) {
$("txtContent").value += "\r\n" + msg;
$("txtContent").scrollTop=$("txtContent").scrollHeight;
console.log(msg);
var li=msg.split("=||..");
console.log(li)
if(li.length==2){
//console.log($("wd").innerHtml)
$("wda").href="http://"+$("serverIP").value+li[1];
}
// var scrollHeight = $("txtContent").scrollHeight;
// var height = $("txtContent").offsetHeight;
// console.log(height);
// console.log(scrollHeight)
// if(height < scrollHeight){
// $("txtContent").style.height = $("txtContent").scrollHeight+'px';
// }
}
window.onload = function(){
$("txtContent").style.height = window.screen.height * 0.5 + 'px';
console.log(window.screen.height);
}
document.onkeydown=function(event) { if (event.keyCode == 13) { send();} }
</script>
</html>
<!--
{
"syncId": -1,
"command": "sendFriendMessage",
"subCommand": null,
"content": {
"target":114514,
"messageChain":[{ "type":"Plain", "text":"hello\n" }]
}
}
-->