-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.html
221 lines (201 loc) · 5.55 KB
/
chat.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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
<!DOCTYPE html>
<html>
<head>
<title>StudyTalk</title>
<style type="text/css">
body {
text-align:center;
}
#wrapper{
padding-bottom:25px;
background:#007FFF;
width:80%;
border:1px solid #000;
height: 600px;
float: right;
}
#DonateBox{
background: #007FFF;
width:7%;
border: 1px solid #000;
height: auto;
float: left;
}
#listofusers{
background: #3BDA92;
width:12%;
border: 1px solid #000;
height: auto;
float: left;
}
#chatbox {
text-align:left;
margin:auto;
margin-bottom:25px;
padding:10px;
background:#fff;
height:500px;
width:1000px;
border:1px;
overflow:auto;
}
.name{
text-decoration-color: #28DE85;
}
#usermsg, #namemsg {
width:400px;
border:1px solid #ACD8F0;
}
#submit { width: 60px; }
#menu { padding:12.5px 25px 12.5px 25px; }
#welcome { float:left; }
#logout { float:right; }
.black {
color: black;
}
.red {
color: red;
}
.blue {
color: blue;
}
.green{
color: green;
}
.purple{
color: purple;
}
.Azur{
color: #007FFF;
}
</style>
</head>
<body>
<div id="wrapper">
<div id="menu">
<p id="welcome"> There are currently o users connected!</p>
<p id="logout">Welcome</p>
</div>
<div id="chatbox">
</div>
<form name="message" id="message" method="">
<input name="messagebox" type="text" id="usermsg"/>
<select id="color">
<option value="black">Select a text color</option>
<option value="black">Black</option>
<option value="red">Red</option>
<option value="blue">Blue</option>
<option value="green">Green</option>
<option value="purple">Purple</option>
<option value="Azur">Azur</option>
</select>
<!-- <input type="file" onchange="previewFile()"><br> -->
<input name="submitmsg" type="button" id="submitmsg" value="Send"/>
</form>
</div>
<div id="listofusers">
<p>Online Users</p>
</div>
<div id="DonateBox">
<button type="button" id="donateBtn">Donate</button>
<p>Leaderboard</p>
<div id="lb">
</div>
</div>
<script src="/socket.io/socket.io.js"></script>
<script>
var socket = io(); // creates new socket (client)
</script>
<script src="http://code.jquery.com/jquery-3.2.1.js"></script>
<script>
$(function () {
let username;
$("#donateBtn").click(function(){
socket.emit('donateHandler', 1);
});
$("#submitmsg").click(function(){
sendMessage();
return false;
});
$(document).on('keyup keypress', 'form input', function(e) {
if(e.which === 13) {// when press enter key
e.preventDefault(); // prevents submitting
sendMessage();
return false;
}
});
// function previewFile(){
// var preview = document.querySelector('img'); //selects the query named img
// var file = document.querySelector('input[type=file]').files[0]; //sames as here
// var reader = new FileReader();
// reader.onloadend = function () {
// preview.src = reader.result;
// }
// if (file) {
// reader.readAsDataURL(file); //reads the data as a URL
// } else {
// preview.src = "";
// }
// }
function sendMessage(){ // send message to server
if($("#usermsg").val() !== ""){
let msg = $("#usermsg").val();
if(msg.indexOf("<3") !== -1) {
msg = msg.replace(/<3/g, "♥")
}
if(msg.indexOf(":tableflip:") !== -1){
msg = msg.replace(/:tableflip:/g,"(╯°□°)╯︵ ┻━┻");
}
if(msg.indexOf(":shrug:") !== -1){
msg = msg.replace(/:shrug:/g, "¯"+"\\"+"_(ツ)_/¯");
}
if(msg.indexOf(":flipallthemtables:") !== -1){
msg = msg.replace(/:flipallthemtables:/g, "┻━┻︵ \\(°□°)/ ︵ ┻━┻");
}
if(msg.indexOf(":smooth:") !== -1){
msg = msg.replace(/:smooth:/g,"(づ  ̄ ³ ̄)づ ⓈⓂⓄⓄⓉⒽ");
}
if(msg === "/clear"){
socket.emit('chat', "/clear"); // sends /clear to server
$("#usermsg").val("");
return;
}
socket.emit('chat', msg, $("#color").val()); // client sends message and color to server
$("#usermsg").val(""); // clears the textbox
$("#chatbox").scrollTop($("#chatbox")[0].scrollHeight); //auto scroll
}
}
socket.on('chat', function(msg){ //when client receives a msg
if(msg === "/clear"){ //if client receives /clear
$("#chatbox").html(''); //clear the chatbox
return;
}
$("#chatbox").append(msg);
$("#chatbox").scrollTop($("#chatbox")[0].scrollHeight); //auto scroll
});
socket.on('clientDisplay', function(title){ // when client receives the updated number of connected clients
$("p#welcome").html(title);
});
socket.on('redirect', function(destination) { //redirects client to nickname area
window.location.href = destination;
});
socket.on('topright', function(toprightmsg){
$("p#logout").html(toprightmsg); // the welcome *username*
});
socket.on('clearlist', function(filler){
$("div#listofusers").html(''); //clears list to prevent double listing
$("div#listofusers").append("<p>USER-LIST</p>");
});
socket.on('onlineuser', function(username){
$("div#listofusers").append("<p>" + username + "</p>"); //appends all nicknames from array
});
socket.on('donateHandler', function(val){ // when recieve the nickname and clicks
$("#lb").append(val);
});
socket.on('clearDonate', function(filler){
$("#lb").html('');
});
});
</script>
</body>
</html>