-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat_link_site.html
179 lines (177 loc) · 6.33 KB
/
chat_link_site.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
<!DOCTYPE html>
<html>
<head>
<link rel="preconnect" href="https://fonts.gstatic.com">
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+JP:wght@300&display=swap" rel="stylesheet">
<style type="text/css">
body{
background-color: lightgray;
}
#title{
margin:auto;
background: darkgrey;
color:black;
font-size: 3rem;
text-align: center;
border: 1rem solid black;
padding: 0.25rem;
font-family: 'Noto Sans JP', sans-serif;
}
#chat{
font-family: 'Noto Sans JP', sans-serif;
overflow: auto;
height: 45vh;
margin:auto;
padding: 1rem;
border:1rem solid black;
border-top: 0rem solid black;
background-color: darkgrey;
}
#user{
display: inline-block;
size: 50%;
}
#send{
font-family: 'Noto Sans JP', sans-serif;
display: block;
margin : 0 auto;
}
#message{
font-family: 'Noto Sans JP', sans-serif;
margin:auto;
display: block;
margin : 0 auto;
}
#passkey{
text-align:center;
font-family: 'Noto Sans JP', sans-serif;
display: block;
margin : 0 auto;
}
#passMSG{
text-align: center;
}
p, input {
font-family: 'Noto Sans JP', sans-serif;
}
#emoji-show {
border: 0.25rem solid black;
padding: 0.15rem;
background-color: darkgrey;
width: fit-content;
}
</style>
<title>ChatLink</title>
</head>
<h1 id="title">Chat Link</h1>
<div id="chat"></div>
<input type="button" value="Emoji", onclick="toggleDiv('emoji-show')">
<div id="emoji-show">
<!--emojis: make the parameters for sendEmoji the button id and the value their respective emoji-->
<input class="emoji-btns" type="button" id="sunglasses" value="😎", onclick="sendEmoji('sunglasses')">
<input class="emoji-btns" type="button" id="crying" value="😢", onclick="sendEmoji('crying')">
<input class="emoji-btns" type="button" id="angry" value="😠", onclick="sendEmoji('angry')">
<input class="emoji-btns" type="button" id="confused" value="😕", onclick="sendEmoji('confused')">
<input class="emoji-btns" type="button" id="smile" value="😄", onclick="sendEmoji('smile')">
<input class="emoji-btns" type="button" id="rofl" value="🤣", onclick="sendEmoji('rofl')">
<input class="emoji-btns" type="button" id="flushed" value="😳", onclick="sendEmoji('flushed')">
<input class="emoji-btns" type="button" id="pensive" value="😔", onclick="sendEmoji('pensive')">
<input class="emoji-btns" type="button" id="disappointed" value="😞", onclick="sendEmoji('disappointed')">
<input class="emoji-btns" type="button" id="smirk" value="😏", onclick="sendEmoji('smirk')">
<input class="emoji-btns" type="button" id="nervous" value="😅", onclick="sendEmoji('nervous')">
<input class="emoji-btns" type="button" id="middle_finger" value="🖕", onclick="sendEmoji('middle_finger')">
<input class="emoji-btns" type="button" id="sad" value="🙁", onclick="sendEmoji('sad')">
</div><br>
<input type="text" id="message" width="1000" autocomplete="off">
<input type="button" id="send" value="Send", onclick="messageSend()">
<p id="passMSG">Put your passkey here: </p><input type="password" id="passkey" width="1000">
<p id="user"></p><br>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
var cachedMessages = ['a','b']
$("#user").hide()
//is hidden by default
$("#chat").hide();
$("#emoji-show").hide();
//message updating
setInterval(() => {
fetch("http://sserve.cc:85/messages_raw", {
method: "GET",
headers: {
'passkey': $("#passkey").val()
}
}).then(res => res.json()).then(res => {
if(cachedMessages.join("")==res.join("")){
if(cachedMessages == "")throw validationError;
return;
}else{
cachedMessages=res;
$("#chat").html("");
res.forEach(elem => {
let origin;
switch (elem[1]) {
case 0:
origin = "D";
break;
case 1:
origin = "C";
break;
case 2:
origin = "C";
break;
}
elem = `${elem[0]}[${origin}]: ${elem[2]}`;
$("#chat").append(elem+"<br>") ? res.indexOf(elem) == res.length : $("#chat").append(elem);
});
$('#chat').scrollTop($('#chat')[0].scrollHeight);
$("#passMSG").html("Put your passkey here: ");
//user logging
fetch("http://sserve.cc:85/user", {
method: "GET",
headers: {
'passkey': $("#passkey").val()
}
}).then(res => res.json()).then(userData =>{
if($("#user:hidden")){
$("#user").html(`Logged in as ${userData[1]}.`);
$("#user").show();
}else return;
});
}
}).catch(err => {
$("#passMSG").html("Put your passkey here: <br>Please enter a valid passkey!");
$("#user").hide();
});
$("#chat").show();
//the :empty is shorthand for if(chat is empty)
$("#chat:empty").hide();
}, 1000);
//send message
function messageSend(){
let message = $("#message").val();
if(!message)return
fetch("http://sserve.cc:85/message",{
method:"PUT",
headers:{
"passkey": $("#passkey").val(),
},
body: $("#message").val(),
});
$("#message").val("");
}
//emojis
function sendEmoji(emoji){
$("#message").val($("#message").val()+" "+$(`#${emoji}`).val());
}
//toggle div visibility
function toggleDiv(id){
$(`#${id}`).toggle();
}
//enter support
$(document).keypress(function(e){
if (e.which == 13){
$("#send").click();
}
});
</script>
</html>