-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathhome.html
More file actions
135 lines (123 loc) · 3.84 KB
/
home.html
File metadata and controls
135 lines (123 loc) · 3.84 KB
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Chat Example</title>
<style>
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: 'Arial', sans-serif;
display: flex;
flex-direction: column;
height: 100vh;
background: linear-gradient(135deg, #f3e5f5, #e1bee7);
}
#log {
background: white;
margin: 1em;
padding: 1em;
border-radius: 8px;
flex: 1;
overflow-y: auto;
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2);
}
#form {
display: flex;
margin: 1em;
background: #ffffff;
border-radius: 8px;
box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
}
#msg {
flex: 1;
padding: 10px;
border: 1px solid #ccc;
border-radius: 5px;
font-size: 16px;
margin-right: 10px;
transition: border-color 0.3s;
outline: none;
}
#msg:focus {
border-color: #6a1b9a;
box-shadow: 0 0 5px rgba(106, 27, 154, 0.5);
}
input[type="submit"] {
padding: 10px 15px;
background-color: #6a1b9a;
color: white;
border: none;
border-radius: 5px;
cursor: pointer;
transition: background-color 0.3s;
}
input[type="submit"]:hover {
background-color: #4a0072;
}
@media (max-width: 600px) {
#msg {
font-size: 14px;
}
input[type="submit"] {
padding: 8px 12px;
}
}
</style>
<script>
window.onload = function () {
var conn;
var msg = document.getElementById("msg");
var log = document.getElementById("log");
function appendLog(item) {
var doScroll = log.scrollTop > log.scrollHeight - log.clientHeight - 1;
log.appendChild(item);
if (doScroll) {
log.scrollTop = log.scrollHeight - log.clientHeight;
}
}
document.getElementById("form").onsubmit = function () {
if (!conn) {
return false;
}
if (!msg.value) {
return false;
}
conn.send(msg.value);
msg.value = "";
return false;
};
if (window["WebSocket"]) {
conn = new WebSocket("ws://" + document.location.host + "/ws");
conn.onclose = function () {
var item = document.createElement("div");
item.innerHTML = "<b>Connection closed.</b>";
appendLog(item);
};
conn.onmessage = function (evt) {
var messages = evt.data.split('\n');
for (var i = 0; i < messages.length; i++) {
var item = document.createElement("div");
item.innerText = messages[i];
appendLog(item);
}
};
} else {
var item = document.createElement("div");
item.innerHTML = "<b>Your browser does not support WebSockets.</b>";
appendLog(item);
}
};
</script>
</head>
<body>
<div id="log"></div>
<form id="form">
<input type="text" id="msg" placeholder="Type your message..." size="64" autofocus />
<input type="submit" value="Send" />
</form>
</body>
</html>