-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.html
119 lines (106 loc) · 3.22 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
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
<!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 - 10px);
overflow-y: scroll;
padding-bottom: 40px;
position: absolute;
top: 0;
left: 0;
}
.send-container {
width: 100vw;
height: max-content;
position: absolute;
bottom: 0;
left: 0;
}
.send-container input,
.send-container input:active,
.send-container input:focus {
width: calc(100vw - 40px);
border: none;
border-top: 1px solid var(--foreground);
height: calc(50px - 40px);
padding: 20px;
font-size: 10px;
font-family: monospace;
background: var(--background);
color: var(--foreground);
outline: none;
}
.message {
max-width: 500px;
padding: 10px;
padding-bottom: 0px;
font-size: 10px;
transition: 250ms;
opacity: 1;
}
.message-fadein {
padding-left: 0;
opacity: 0;
}
</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('ws://localhost:23828'/*'wss://chatws.strayfade.com'*/);
let firstRequest = true
socket.onmessage = async (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-fadein"
message.textContent = Line;
messages.appendChild(message);
if (!firstRequest) {
await new Promise(r => setTimeout(r, 100));
}
message.classList.remove("message-fadein")
}
if (firstRequest) {
firstRequest = false
}
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>