forked from bluebrown/web-shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
44 lines (42 loc) · 1.11 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
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="/node_modules/xterm/css/xterm.css" />
<script src="/node_modules/xterm/lib/xterm.js"></script>
<style>
body {
font-family: monospace;
text-align: center;
padding-top: 3rem;
}
.container {
max-width: fit-content;
margin: 0 auto;
}
</style>
<script type="module" defer>
const ws = new WebSocket("ws://" + location.host + "/socket");
const term = new Terminal();
term.open(document.getElementById("terminal"));
term.onData((data) => ws.send(data));
ws.onmessage = ({ data }) => {
const stream = data.stream();
const reader = stream.getReader();
reader
.read()
.then(function processText({ done, value }) {
if (done) return;
term.write(value);
return reader.read().then(processText);
})
.catch(console.error);
};
</script>
</head>
<body>
<div class="container">
<h1>Web Shell</h1>
<div id="terminal"></div>
</div>
</body>
</html>