-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
94 lines (83 loc) · 2.55 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
92
93
94
<!DOCTYPE html>
<head>
<style>
:root {
--background: black;
--foreground: white;
}
body {
margin: 0;
overflow: hidden;
font-family: monospace;
background: var(--background);
color: var(--foreground);
}
main {
width: 100vw;
height: 100vh;
position: absolute;
left: 0;
top: 0;
}
.messages-container {
width: 100vw;
height: calc(100vh - 50px - 40px);
overflow-y: scroll;
padding-bottom: 40px;
}
.send-container {
width: 100vw;
height: 100px;
}
.send-container input, .send-container input:active, .send-container input:focus {
width: calc(100vw - 80px);
border: none;
border-top: 1px solid var(--foreground);
height: calc(50px - 40px);
padding: 20px 40px;
font-size: 10px;
font-family: monospace;
background: var(--background);
color: var(--foreground);
outline: none;
}
.message {
padding: 10px;
padding-bottom: 0px;
font-size: 10px;
}
</style>
</head>
<body>
<main>
<div class="messages-container">
</div>
<div class="send-container">
<input type="text" id="send-input" placeholder="Type message"/>
</div>
</main>
<script>
const socket = new WebSocket('wss://chatws.strayfade.com');
socket.onmessage = (event) => {
const messages = document.getElementsByClassName('messages-container')[0];
const Lines = event.data.toString().split("\u0000")
for (const Line of Lines) {
if (Line.length < 2) continue;
let message = document.createElement('div');
message.className = "message"
message.textContent = Line;
messages.appendChild(message);
}
messages.scrollTop = messages.scrollHeight
};
socket.onopen = () => {
socket.send(`\u0000`)
}
document.getElementById('send-input').addEventListener("keydown", (event) => {
if (event.keyCode == 13 || event.key == "Enter") {
socket.send(document.getElementById('send-input').value)
document.getElementById('send-input').value = ""
}
})
</script>
</body>