-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathchat.html
More file actions
305 lines (290 loc) · 15.5 KB
/
chat.html
File metadata and controls
305 lines (290 loc) · 15.5 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
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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
<!DOCTYPE html>
<html>
<head>
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Titan+One&display=swap" rel="stylesheet">
<link href="https://fonts.googleapis.com/css2?family=Nunito&family=Poppins:wght@500&display=swap" rel="stylesheet">
<link rel="stylesheet" href="style.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.4/css/all.min.css">
<!-- Firebase JavaScript SDK -->
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-app.js"></script>
<script src="https://www.gstatic.com/firebasejs/8.10.0/firebase-database.js"></script>
<title>Stats | Anolet</title>
<style>
div {
display: block;
unicode-bidi: isolate;
}
@keyframes rainbow {
0% { background-position: 0% 50%; }
100% { background-position: 100% 50%; }
}
.rainbow-text {
display: inline-block;
background: linear-gradient(to right, #FF0000, #FF7F00, #FFFF00, #00FF00, #0000FF, #4B0082, #9400D3);
background-size: 200% 100%;
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
animation: rainbow 5s linear infinite;
}
.badge {
width: 20px; /* Set badge width to 45px */
}
#chat-container { }
#chat-messages {
gap: 5px;
max-height: 80vh;
overflow-y: auto;
margin: 20px auto;
color: white;
font-family: Impact, Haettenschweiler, 'Arial Narrow Bold', sans-serif;
font-weight: 550;
border-radius: 5px;
font-size: 20px;
width: 1000%;
padding: 10px;
}
#message-input {
width: 800px;
}
#send-button {
width: 100px;
}
.bg_img {
position: absolute;
width: 200%;
height: 200%;
top: 50%;
left: 50%;
z-index: -9999;
background-size: 550px;
background-position: -100px -100px;
background-image: url("https://ac.blooket.com/dashboard/assets/BlookCheckers-BykpA7vd.png");
transform: translate(-50%, -50%) rotate(15deg);
opacity: 0.1;
}
#chat{
margin-left: 40px;
margin-top: -160px;
}
</style>
</head>
<body style="background-color: #336c4c; overflow: hidden;">
<img alt="Blooks Background" class="bg_img">
<div class="side_bar">
<div class="anolet_text" id="container">
<a class="logo_link" style="color:#fff; text-decoration: none;" href="index.html">Anolet</a>
</div>
<a class="page_button_selected"></a>
<div class="stats_selector">
<div class="stats_text">
<a href="stats.html" style="color:#fff; text-decoration: none;" class="link">Stats</a>
</div>
<svg aria-hidden="true" focusable="false" class="stats_icon" role="img" viewBox="0 0 512 512"><path fill="white" d="M32 32c17.7 0 32 14.3 32 32V400c0 8.8 7.2 16 16 16H480c17.7 0 32 14.3 32 32s-14.3 32-32 32H80c-44.2 0-80-35.8-80-80V64C0 46.3 14.3 32 32 32zm96 96c0-17.7 14.3-32 32-32l192 0c17.7 0 32 14.3 32 32s-14.3 32-32 32l-192 0c-17.7 0-32-14.3-32-32zm32 64H288c17.7 0 32 14.3 32 32s-14.3 32-32 32H160c-17.7 0-32-14.3-32-32s14.3-32 32-32zm0 96H416c17.7 0 32 14.3 32 32s-14.3 32-32 32H160c-17.7 0-32-14.3-32-32s14.3-32 32-32z"></path></svg>
</div>
<div class="leaderboard_selector">
<div class="leaderboard_text">
<a href="leader.html" style="color:#fff; text-decoration: none;" class="link">Leaderboard</a>
</div>
<svg aria-hidden="true" focusable="false" class="leaderboard_icon" role="img" viewBox="0 0 576 512"><path fill="white" d="M400 0H176c-26.5 0-48.1 21.8-47.1 48.2c.2 5.3 .4 10.6 .7 15.8H24C10.7 64 0 74.7 0 88c0 92.6 33.5 157 78.5 200.7c44.3 43.1 98.3 64.8 138.1 75.8c23.4 6.5 39.4 26 39.4 45.6c0 20.9-17 37.9-37.9 37.9H192c-17.7 0-32 14.3-32 32s14.3 32 32 32H384c17.7 0 32-14.3 32-32s-14.3-32-32-32H357.9C337 448 320 431 320 410.1c0-19.6 15.9-39.2 39.4-45.6c39.9-11 93.9-32.7 138.2-75.8C542.5 245 576 180.6 576 88c0-13.3-10.7-24-24-24H446.4c.3-5.2 .5-10.4 .7-15.8C448.1 21.8 426.5 0 400 0zM48.9 112h84.4c9.1 90.1 29.2 150.3 51.9 190.6c-24.9-11-50.8-26.5-73.2-48.3c-32-31.1-58-76-63-142.3zM464.1 254.3c-22.4 21.8-48.3 37.3-73.2 48.3c22.7-40.3 42.8-100.5 51.9-190.6h84.4c-5.1 66.3-31.1 111.2-63 142.3z"></path></svg>
</div>
<div class="blooks_selector">
<div class="blooks_text">
<a href="blooks.html" style="color:#fff; text-decoration: none;" class="link">Blooks</a>
</div>
<svg aria-hidden="true" focusable="false" class="blooks_icon" role="img" viewBox="0 0 512 512"><path fill="white" d="M176 56V96H336V56c0-4.4-3.6-8-8-8H184c-4.4 0-8 3.6-8 8zM128 96V56c0-30.9 25.1-56 56-56H328c30.9 0 56 25.1 56 56V96v32V480H128V128 96zM64 96H96V480H64c-35.3 0-64-28.7-64-64V160c0-35.3 28.7-64 64-64zM448 480H416V96h32c35.3 0 64 28.7 64 64V416c0 35.3-28.7 64-64 64z"></path></svg>
</div>
<div class="market_selector">
<div class="market_text">
<a href="market.html" style="color:#fff; text-decoration: none;" class="link">Market</a>
</div>
<svg aria-hidden="true" focusable="false" class="market_icon" role="img" viewBox="0 0 576 512"><path fill="white" d="M547.6 103.8L490.3 13.1C485.2 5 476.1 0 466.4 0H109.6C99.9 0 90.8 5 85.7 13.1L28.3 103.8c-29.6 46.8-3.4 111.9 51.9 119.4c4 .5 8.1 .8 12.1 .8c26.1 0 49.3-11.4 65.2-29c15.9 17.6 39.1 29 65.2 29c26.1 0 49.3-11.4 65.2-29c15.9 17.6 39.1 29 65.2 29c26.2 0 49.3-11.4 65.2-29c16 17.6 39.1 29 65.2 29c4.1 0 8.1-.3 12.1-.8c55.5-7.4 81.8-72.5 52.1-119.4zM499.7 254.9l-.1 0c-5.3 .7-10.7 1.1-16.2 1.1c-12.4 0-24.3-1.9-35.4-5.3V384H128V250.6c-11.2 3.5-23.2 5.4-35.6 5.4c-5.5 0-11-.4-16.3-1.1l-.1 0c-4.1-.6-8.1-1.3-12-2.3V384v64c0 35.3 28.7 64 64 64H448c35.3 0 64-28.7 64-64V384 252.6c-4 1-8 1.8-12.3 2.3z"></path></svg>
</div>
<div class="puzzles_selector">
<div class="puzzles_text">
<a href="chat.html" style="color:#fff; text-decoration: none;" class="link">Chat</a>
</div>
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg id="chat" width="25px" height="800px" viewBox="0 0 24 24" fill="white" xmlns="http://www.w3.org/2000/svg">
<path d="M17 3.33782C15.5291 2.48697 13.8214 2 12 2C6.47715 2 2 6.47715 2 12C2 13.5997 2.37562 15.1116 3.04346 16.4525C3.22094 16.8088 3.28001 17.2161 3.17712 17.6006L2.58151 19.8267C2.32295 20.793 3.20701 21.677 4.17335 21.4185L6.39939 20.8229C6.78393 20.72 7.19121 20.7791 7.54753 20.9565C8.88837 21.6244 10.4003 22 12 22C17.5228 22 22 17.5228 22 12C22 10.1786 21.513 8.47087 20.6622 7" stroke="#1C274C" stroke-width="1.5" stroke-linecap="round"/>
<path d="M8 12H8.009M11.991 12H12M15.991 12H16" stroke="#1C274C" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
</svg> </div>
<div class="panel_selector">
<div class="panel_text">
<a href="Rooms.html" style="color:#fff; text-decoration: none;" class="link">Trading Rooms</a>
<?xml version="1.0" encoding="utf-8"?><!-- Uploaded to: SVG Repo, www.svgrepo.com, Generator: SVG Repo Mixer Tools -->
<svg id="Trade" width="35px" height="800px" viewBox="0 0 16 16" xmlns="http://www.w3.org/2000/svg" fill="white"><path d="M14.63 7L13 3h1V2H9V1H8v1H3v1h1L2.38 7H2v1h.15c.156.498.473.93.9 1.23a2.47 2.47 0 0 0 2.9 0A2.44 2.44 0 0 0 6.86 8H7V7h-.45L4.88 3H8v8H6l-.39.18-2 2.51.39.81h9l.39-.81-2-2.51L11 11H9V3h3.13l-1.67 4H10v1h.15a2.48 2.48 0 0 0 4.71 0H15V7h-.37zM5.22 8.51a1.52 1.52 0 0 1-.72.19 1.45 1.45 0 0 1-.71-.19A1.47 1.47 0 0 1 3.25 8h2.5a1.52 1.52 0 0 1-.53.51zM5.47 7h-2l1-2.4 1 2.4zm5.29 5L12 13.5H5L6.24 12h4.52zm1.78-7.38l1 2.4h-2l1-2.4zm.68 3.91a1.41 1.41 0 0 1-.72.19 1.35 1.35 0 0 1-.71-.19 1.55 1.55 0 0 1-.54-.53h2.5a1.37 1.37 0 0 1-.53.53z"/></svg> </div>
<div>
<a href="login.html" onclick="clearCookies()"><button class="logout_button">Logout</button></a>
</div>
<a href="login.html" onclick="clearCookies()"><button class="logout_button">Logout</button></a>
</div>
<div id="chat-container">
<div id="chat-messages" style="margin-top: -675px; margin-left: 215px; color: white; font-family: Nunito; font-weight: 550; border-radius: 5px; font-weight: 1000; font-size: 20px;"></div>
<button style=" display: none;" id="send-button">Send</button>
<input style="height: 70px; width: 1800px; margin-top: -0px; font-weight: 1000; color: white; margin-left: 210px; background-color: rgb(30, 58, 30); border: none;" type="text" id="message-input" placeholder="Type your message..."> </div>
<script type="module">
import { initializeApp } from "https://www.gstatic.com/firebasejs/10.10.0/firebase-app.js";
import { getDatabase, ref, push, onChildAdded, remove } from "https://www.gstatic.com/firebasejs/10.10.0/firebase-database.js";
import { getFirestore, doc, getDoc } from "https://www.gstatic.com/firebasejs/10.10.0/firebase-firestore.js";
const firebaseConfig = {
apiKey: "AIzaSyCOIKlP9YhtX9xa5aoggmsrWwavlW-XuzI",
authDomain: "cosmik-7c124.firebaseapp.com",
databaseURL: "https://cosmik-7c124-default-rtdb.firebaseio.com",
projectId: "cosmik-7c124",
storageBucket: "cosmik-7c124.appspot.com",
messagingSenderId: "412506429662",
appId: "1:412506429662:web:9ca3e17199297df7384a4f",
measurementId: "G-R7K0LTHCK3"
};
const app = initializeApp(firebaseConfig);
const database = getDatabase(app);
const firestore = getFirestore(app);
const messagesRef = ref(database, 'messages');
const chatMessages = document.getElementById('chat-messages');
const messageInput = document.getElementById('message-input');
const sendButton = document.getElementById('send-button');
function getCookie(cookieName) {
const name = `${cookieName}=`;
const decodedCookie = decodeURIComponent(document.cookie);
const cookieArray = decodedCookie.split(';');
for(let i = 0; i < cookieArray.length; i++) {
let cookie = cookieArray[i];
while (cookie.charAt(0) === ' ') {
cookie = cookie.substring(1);
}
if (cookie.indexOf(name) === 0) {
return cookie.substring(name.length, cookie.length);
}
}
return '';
}
function scrollToBottom() {
chatMessages.scrollTop = chatMessages.scrollHeight;
}
function playNotificationSound() {
const audio = new Audio('Pinging.mp3');
audio.play();
}
async function sendMessage() {
const message = messageInput.value.trim();
if (message !== '') {
try {
const username = getCookie('username');
const roles = getCookie('roles');
if (!username || !roles) {
console.error("Username or roles not found in cookies.");
return;
}
const userDoc = await getDoc(doc(firestore, 'users', username));
const profilePicture = userDoc.exists() ? userDoc.data().profilePicture : '';
const badgesHtml = await getUserBadges(username);
if (message.startsWith('/ban')) {
if (['Helper', 'Admin', 'Mod', 'Owner'].includes(roles)) {
const targetUser = message.split(' ')[1];
displaySystemMessage(`${username} (${roles}) has banned ${targetUser}`);
} else {
displaySystemMessage("You do not have permission to use this command.");
}
} else if (message.startsWith('/tokens')) {
const targetUser = message.split(' ')[1];
if (targetUser) {
displaySystemMessage(`Requested tokens for ${targetUser}`);
} else {
displaySystemMessage("Please specify a user.");
}
} else if (message.startsWith('/user')) {
const targetUser = message.split(' ')[1];
if (targetUser) {
displaySystemMessage(`Requested info for ${targetUser}`);
} else {
displaySystemMessage("Please specify a user.");
}
} else if (message.startsWith('/Dchat') && roles === 'Owner') {
deleteAllMessages();
displaySystemMessage(`All messages have been deleted by ${username} (${roles}).`);
} else {
await push(messagesRef, {
username: username,
roles: roles,
message: message,
profilePicture: profilePicture,
badges: badgesHtml,
timestamp: new Date().toISOString()
});
if (message.includes(`@${username}`)) {
playNotificationSound();
}
}
messageInput.value = '';
} catch (error) {
if (error.code === 'quota-exceeded') {
console.error("Quota exceeded. Please try again later.");
} else {
console.error("Error sending message:", error);
}
}
}
}
function displaySystemMessage(message) {
const systemMessageDiv = document.createElement('div');
systemMessageDiv.textContent = message;
systemMessageDiv.style.color = 'red';
chatMessages.appendChild(systemMessageDiv);
scrollToBottom();
}
async function getUserBadges(username) {
const userDoc = await getDoc(doc(firestore, 'users', username));
if (userDoc.exists()) {
const badges = userDoc.data().badges || [];
return badges.map(badgeUrl => `<img src="${badgeUrl}" alt="Badge" class="badge">`).join('');
} else {
console.log("No such document!");
return '';
}
}
function generateRainbowText(text) {
return `<span class="rainbow-text">${text}</span>`;
}
sendButton.addEventListener('click', sendMessage);
messageInput.addEventListener('keypress', (e) => {
if (e.key === 'Enter') {
sendMessage();
}
});
function displayMessage(messageData) {
const messageDiv = document.createElement('div');
messageDiv.style.display = 'flex';
messageDiv.style.alignItems = 'center';
const profileImg = document.createElement('img');
profileImg.src = messageData.profilePicture || 'default_profile_picture_url';
profileImg.alt = `${messageData.username}'s profile picture`;
profileImg.style.width = '65px';
profileImg.style.height = '70px';
profileImg.style.marginRight = '10px';
const messageText = document.createElement('div');
const usernameHtml = messageData.roles === 'Owner' ? generateRainbowText(messageData.username) : messageData.username;
messageText.innerHTML = `${usernameHtml} (${messageData.roles}): ${messageData.message} ${messageData.badges}`;
messageDiv.appendChild(profileImg);
messageDiv.appendChild(messageText);
chatMessages.appendChild(messageDiv);
scrollToBottom();
}
function deleteAllMessages() {
remove(messagesRef)
.then(() => {
console.log('All messages deleted.');
chatMessages.innerHTML = '';
})
.catch((error) => {
console.error('Error deleting messages:', error);
});
}
onChildAdded(messagesRef, (snapshot) => {
const messageData = snapshot.val();
displayMessage(messageData);
});
</script>
</body>
</html>