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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<!DOCTYPE html>
|
2 |
+
<html>
|
3 |
+
<head>
|
4 |
+
<meta charset="utf-8">
|
5 |
+
<title>Fast Messaging by [Glz_SQL]</title>
|
6 |
+
<script src="https://cdnjs.cloudflare.com/ajax/libs/socket.io/4.0.1/socket.io.js"></script>
|
7 |
+
<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
|
8 |
+
<style type="text/css">
|
9 |
+
body {
|
10 |
+
margin: 0;
|
11 |
+
padding: 0;
|
12 |
+
font-family: Arial, sans-serif;
|
13 |
+
background-color: #f0f0f0;
|
14 |
+
}
|
15 |
+
|
16 |
+
.header {
|
17 |
+
text-align: center;
|
18 |
+
padding: 20px;
|
19 |
+
background-color: #3498db;
|
20 |
+
color: #ffffff;
|
21 |
+
}
|
22 |
+
|
23 |
+
.app {
|
24 |
+
position: relative;
|
25 |
+
padding: 20px;
|
26 |
+
}
|
27 |
+
|
28 |
+
.message-container {
|
29 |
+
position: relative;
|
30 |
+
}
|
31 |
+
|
32 |
+
.message-container textarea {
|
33 |
+
width: 100%;
|
34 |
+
padding: 10px;
|
35 |
+
border: 1px solid #ccc;
|
36 |
+
background-color: #ffffff;
|
37 |
+
}
|
38 |
+
|
39 |
+
.message-input {
|
40 |
+
background-color: transparent;
|
41 |
+
width: 100%;
|
42 |
+
height: 175px;
|
43 |
+
/*border: 1px solid #ccc;*/
|
44 |
+
}
|
45 |
+
|
46 |
+
|
47 |
+
.message-box {
|
48 |
+
position: relative;
|
49 |
+
width: calc(33% + 100px);
|
50 |
+
height: auto;
|
51 |
+
padding: calc(4% + 20px);
|
52 |
+
border-radius: 5px;
|
53 |
+
font-size: 24pt;
|
54 |
+
margin: 0 0 20px 20px;
|
55 |
+
white-space: pre;
|
56 |
+
white-space: pre-line;
|
57 |
+
|
58 |
+
}
|
59 |
+
|
60 |
+
@media (orientation: portrait) {
|
61 |
+
.message-box {
|
62 |
+
margin-bottom: 100px;
|
63 |
+
}
|
64 |
+
}
|
65 |
+
|
66 |
+
/* Styles pour le mode paysage */
|
67 |
+
@media (orientation: landscape) {
|
68 |
+
.message-box {
|
69 |
+
margin-bottom: 80px;
|
70 |
+
}
|
71 |
+
}
|
72 |
+
.message-box.sent {
|
73 |
+
width: calc(88% - 50px);
|
74 |
+
background-color: #d3d3d3;/*#20efbb; */
|
75 |
+
left: 0%;
|
76 |
+
}
|
77 |
+
|
78 |
+
.message-box.received {
|
79 |
+
width: 85%;
|
80 |
+
background-color: #fff;/*#3498db;*/
|
81 |
+
|
82 |
+
}
|
83 |
+
.message-box.received a {
|
84 |
+
color: #2A58E2;
|
85 |
+
font-size: 18pt;
|
86 |
+
}
|
87 |
+
|
88 |
+
#message-input {
|
89 |
+
position: fixed;
|
90 |
+
bottom: 10px;
|
91 |
+
left: calc(10% + 40px);
|
92 |
+
background-color: transparent;
|
93 |
+
border: solid #000;
|
94 |
+
opacity: 85%;
|
95 |
+
width: calc(70% - 40px);
|
96 |
+
height: calc(3% + 35px);
|
97 |
+
border-radius: 30px;
|
98 |
+
font-size: 32pt;
|
99 |
+
z-index: 9;
|
100 |
+
}
|
101 |
+
|
102 |
+
#message-input:hover {
|
103 |
+
color: #000;
|
104 |
+
background: #d3d3d3;
|
105 |
+
border: solid #3498db;
|
106 |
+
}
|
107 |
+
|
108 |
+
#send-button:hover {
|
109 |
+
color: #fff;
|
110 |
+
background: #20efbb;
|
111 |
+
}
|
112 |
+
|
113 |
+
#send-button {
|
114 |
+
position: fixed;
|
115 |
+
bottom: 12px;
|
116 |
+
left: 84%;
|
117 |
+
background-color: transparent;
|
118 |
+
border: solid #20efbb;
|
119 |
+
width: 150px;
|
120 |
+
height: calc(3% + 50px);
|
121 |
+
border-radius: 20px;
|
122 |
+
font-size: 24pt;
|
123 |
+
z-index: 9;
|
124 |
+
}
|
125 |
+
|
126 |
+
|
127 |
+
#upload-files {
|
128 |
+
position: fixed;
|
129 |
+
bottom: 0px;
|
130 |
+
left: 1%;
|
131 |
+
background-color: transparent;
|
132 |
+
border: solid #20efbb;
|
133 |
+
width: 100px;
|
134 |
+
height: calc(3% + 50px);
|
135 |
+
border-radius: 20px;
|
136 |
+
font-size: 18pt;
|
137 |
+
z-index: 9;
|
138 |
+
overflow: hidden;
|
139 |
+
}
|
140 |
+
|
141 |
+
#custom-upload {
|
142 |
+
display: inline-block;
|
143 |
+
background: transparent;
|
144 |
+
cursor: pointer;
|
145 |
+
position: fixed;
|
146 |
+
bottom: 12px;
|
147 |
+
left: calc(4% - 10px);
|
148 |
+
background-color: transparent;
|
149 |
+
width: calc(100px);
|
150 |
+
/*height: calc(3% + 50px);*/
|
151 |
+
border-radius: 20px;
|
152 |
+
font-size: 18pt;
|
153 |
+
z-index: 4;
|
154 |
+
overflow: hidden;
|
155 |
+
}
|
156 |
+
#upload-files {
|
157 |
+
display: none;
|
158 |
+
}
|
159 |
+
|
160 |
+
#upload-files:hover {
|
161 |
+
color: #fff;
|
162 |
+
background: #20efbb;
|
163 |
+
}
|
164 |
+
|
165 |
+
#user-id-input {
|
166 |
+
position: fixed;
|
167 |
+
top: 80px;
|
168 |
+
left: calc(10% + 40px);
|
169 |
+
background-color: transparent;
|
170 |
+
border: solid #000;
|
171 |
+
opacity: 5%;
|
172 |
+
width: calc(70% - 40px);
|
173 |
+
height: 50px;
|
174 |
+
border-radius: 30px;
|
175 |
+
font-size: 24pt;
|
176 |
+
z-index: 9;
|
177 |
+
display: block;
|
178 |
+
}
|
179 |
+
|
180 |
+
#user-id-input:hover {
|
181 |
+
color: #000;
|
182 |
+
opacity: 80%;
|
183 |
+
background: #d3d3d3;
|
184 |
+
border: solid #3498db;
|
185 |
+
}
|
186 |
+
|
187 |
+
|
188 |
+
|
189 |
+
|
190 |
+
|
191 |
+
|
192 |
+
|
193 |
+
|
194 |
+
|
195 |
+
#menu-button {
|
196 |
+
position: fixed;
|
197 |
+
left: 0;
|
198 |
+
top: 0;
|
199 |
+
width: 50px;
|
200 |
+
height: 100%;
|
201 |
+
background-color: #3498db;
|
202 |
+
color: #ffffff;
|
203 |
+
text-align: center;
|
204 |
+
line-height: 50px;
|
205 |
+
cursor: pointer;
|
206 |
+
z-index: 9999;
|
207 |
+
}
|
208 |
+
|
209 |
+
#menu {
|
210 |
+
position: fixed;
|
211 |
+
left: -150px;
|
212 |
+
top: 0px;
|
213 |
+
width: 150px;
|
214 |
+
height: 100%;
|
215 |
+
background-color: #ffffff;
|
216 |
+
box-shadow: 2px 0 5px rgba(0, 0, 0, 0.2);
|
217 |
+
transition: left 0.3s ease-in-out;
|
218 |
+
overflow-y: auto;
|
219 |
+
padding-top: 45px;
|
220 |
+
padding-left: 20px;
|
221 |
+
padding-right: 20px;
|
222 |
+
z-index: 9997;
|
223 |
+
}
|
224 |
+
|
225 |
+
.menu-item {
|
226 |
+
margin-bottom: 10px;
|
227 |
+
z-index: 9999;
|
228 |
+
cursor: pointer;
|
229 |
+
}
|
230 |
+
|
231 |
+
.menu-item a {
|
232 |
+
color: #0d66e3;
|
233 |
+
}
|
234 |
+
|
235 |
+
#add-button {
|
236 |
+
cursor: pointer;
|
237 |
+
z-index: 9999;
|
238 |
+
}
|
239 |
+
|
240 |
+
#input-container {
|
241 |
+
display: none;
|
242 |
+
margin-top: 10px;
|
243 |
+
z-index: 9998;
|
244 |
+
}
|
245 |
+
|
246 |
+
#toggle-menu-button {
|
247 |
+
position: fixed;
|
248 |
+
left: 5px;
|
249 |
+
top: 10px;
|
250 |
+
width: 30px;
|
251 |
+
height: 30px;
|
252 |
+
background-color: #3498db;
|
253 |
+
color: #ffffff;
|
254 |
+
text-align: center;
|
255 |
+
line-height: 30px;
|
256 |
+
cursor: pointer;
|
257 |
+
z-index: 9999;
|
258 |
+
font-size: 14pt;
|
259 |
+
border: none;
|
260 |
+
}
|
261 |
+
|
262 |
+
#add-button {
|
263 |
+
position: fixed;
|
264 |
+
left: 50px;
|
265 |
+
bottom: 20px;
|
266 |
+
transform: translateX(-50%);
|
267 |
+
width: 40px;
|
268 |
+
height: 40px;
|
269 |
+
background-color: #3498db;
|
270 |
+
color: #ffffff;
|
271 |
+
text-align: center;
|
272 |
+
line-height: 40px;
|
273 |
+
font-size: 20px;
|
274 |
+
cursor: pointer;
|
275 |
+
border-radius: 50%;
|
276 |
+
z-index: 9999;
|
277 |
+
}
|
278 |
+
</style>
|
279 |
+
</head>
|
280 |
+
<body>
|
281 |
+
<div class="header">
|
282 |
+
<h1>Fast Messaging by [Glz_SQL]</h1>
|
283 |
+
</div>
|
284 |
+
<div class="banner"></div>
|
285 |
+
<div class="app">
|
286 |
+
<div class="message-container" id="mmsg">
|
287 |
+
<div class="message-container" id="mmsg2">
|
288 |
+
{{ oldMessage }}
|
289 |
+
</div>
|
290 |
+
<div class="message-input"></div>
|
291 |
+
<input type="hidden" id="user-id-input" placeholder="Saisir un ID" value="general;">
|
292 |
+
<label for="upload-files" id="custom-upload">
|
293 |
+
<img src="/upload-img" width='100px' alt="Upload">
|
294 |
+
</label>
|
295 |
+
<input type="file" id="upload-files" accept="image/*" placeholder="upload" value="Upload"></input>
|
296 |
+
<textarea type="text" id="message-input" placeholder="{{ roomID }}"></textarea>
|
297 |
+
<button id="send-button">Send</button>
|
298 |
+
|
299 |
+
</div>
|
300 |
+
|
301 |
+
|
302 |
+
|
303 |
+
|
304 |
+
|
305 |
+
|
306 |
+
<div style="height: 1000%; width: 90%; background-color: #f0f0f0; position: absolute; bottom: 0px; z-index: -1;"></div>
|
307 |
+
|
308 |
+
|
309 |
+
<button id="toggle-menu-button">≡</button>
|
310 |
+
<div id="menu">
|
311 |
+
{{ rooms }}
|
312 |
+
<!-- Autres éléments du menu -->
|
313 |
+
|
314 |
+
<div id="add-button">+</div>
|
315 |
+
<div id="input-container">
|
316 |
+
<input type="text" id="item-name" placeholder="Nom">
|
317 |
+
<input type="text" id="item-id" placeholder="ID">
|
318 |
+
<button id="ok-button">OK</button>
|
319 |
+
</div>
|
320 |
+
</div>
|
321 |
+
<script type="text/javascript">
|
322 |
+
var socket = io.connect('http://' + document.domain + ':' + location.port); // change by https:// if your use https proxy like replit
|
323 |
+
var uid = "{{ username }}";//document.cookie;//Math.floor(Math.random() * 1000000000);
|
324 |
+
var iid = 0;
|
325 |
+
var roomID = $('#user-id-input').val();
|
326 |
+
var menuVisible = false;
|
327 |
+
var addButton = $('#add-button');
|
328 |
+
var inputContainer = $('#input-container');
|
329 |
+
|
330 |
+
function sendnew(roomid) {
|
331 |
+
roomID = roomid;
|
332 |
+
socket.emit('message', {
|
333 |
+
data: JSON.stringify({
|
334 |
+
message: 'Connected!',
|
335 |
+
usid: uid,
|
336 |
+
roomID: roomid,
|
337 |
+
cookies: document.cookie
|
338 |
+
})
|
339 |
+
});
|
340 |
+
$('#mmsg2').empty();
|
341 |
+
$('#user-id-input').val(roomid);
|
342 |
+
document.getElementById("message-input").placeholder = "Message a envoyer dans " + roomid + "...";
|
343 |
+
menuVisible = !menuVisible;
|
344 |
+
var leftValue = menuVisible ? '0' : '-150px';
|
345 |
+
$('#menu').css('left', leftValue);
|
346 |
+
if (!menuVisible) {
|
347 |
+
addButton.css('display', 'none');
|
348 |
+
$('#toggle-menu-button').css('width', '30px');
|
349 |
+
} else {
|
350 |
+
addButton.css('display', 'inline');
|
351 |
+
$('#toggle-menu-button').css('width', '180px');
|
352 |
+
}
|
353 |
+
}
|
354 |
+
$(document).ready(function() {
|
355 |
+
|
356 |
+
addButton.css('display', 'none');
|
357 |
+
$('#menu-button').on('click', function() {
|
358 |
+
menuVisible = !menuVisible;
|
359 |
+
var leftValue = menuVisible ? '0' : '-150px';
|
360 |
+
$('#menu').css('left', leftValue);
|
361 |
+
});
|
362 |
+
|
363 |
+
addButton.on('click', function() {
|
364 |
+
inputContainer.show();
|
365 |
+
});
|
366 |
+
|
367 |
+
$('#ok-button').on('click', function() {
|
368 |
+
var itemName = $('#item-name').val();
|
369 |
+
var itemId = $('#item-id').val();
|
370 |
+
if (itemName && itemId) {
|
371 |
+
var newItem = $('<div class="menu-item" onclick="sendnew(\'' + itemId + '\');">' + itemName + ' (' + itemId + ')</div>');
|
372 |
+
$('#menu').append(newItem);
|
373 |
+
inputContainer.hide();
|
374 |
+
$('#item-name').val('');
|
375 |
+
$('#item-id').val('');
|
376 |
+
}
|
377 |
+
});
|
378 |
+
|
379 |
+
$('#toggle-menu-button').on('click', function() {
|
380 |
+
menuVisible = !menuVisible;
|
381 |
+
var leftValue = menuVisible ? '0' : '-150px';
|
382 |
+
$('#menu').css('left', leftValue);
|
383 |
+
if (!menuVisible) {
|
384 |
+
addButton.css('display', 'none');
|
385 |
+
$('#toggle-menu-button').css('width', '30px');
|
386 |
+
} else {
|
387 |
+
addButton.css('display', 'inline');
|
388 |
+
$('#toggle-menu-button').css('width', '180px');
|
389 |
+
}
|
390 |
+
});
|
391 |
+
});
|
392 |
+
|
393 |
+
function formatMessage(message, usid) {
|
394 |
+
message = "<" + usid + ">: \n" + message;
|
395 |
+
const words = message.split(" ");
|
396 |
+
const container = document.createElement("div");
|
397 |
+
for (const word of words) {
|
398 |
+
const wordNode = document.createTextNode(word + " ");
|
399 |
+
|
400 |
+
if (word.startsWith("@")) {
|
401 |
+
const username = word.substring(1);
|
402 |
+
const strongNode = document.createElement("strong");
|
403 |
+
strongNode.textContent = "@" + username + " ";
|
404 |
+
container.appendChild(strongNode);
|
405 |
+
} else if (word.match(/^https?:\/\/[^\s/$.?#].[^\s]*$/i)) {
|
406 |
+
const urlNode = document.createElement("a");
|
407 |
+
urlNode.href = word;
|
408 |
+
urlNode.textContent = word + " ";
|
409 |
+
urlNode.target = "_blank";
|
410 |
+
container.appendChild(urlNode);
|
411 |
+
} else {
|
412 |
+
container.appendChild(wordNode);
|
413 |
+
}
|
414 |
+
}
|
415 |
+
|
416 |
+
return container;
|
417 |
+
}
|
418 |
+
document.addEventListener("keydown", KeyCheck);
|
419 |
+
|
420 |
+
function KeyCheck(event) {
|
421 |
+
var KeyID = event.keyCode;
|
422 |
+
switch (KeyID) {
|
423 |
+
case 13:
|
424 |
+
var message = $('#message-input').val();
|
425 |
+
if (message !== '' && message.startsWith("/change-chat-room") === false) {
|
426 |
+
socket.emit('message', {
|
427 |
+
data: JSON.stringify({
|
428 |
+
message: message,
|
429 |
+
usid: uid,
|
430 |
+
roomID: roomID,
|
431 |
+
cookies: document.cookie
|
432 |
+
})
|
433 |
+
});
|
434 |
+
$('#message-input').val('');
|
435 |
+
window.scrollTo(0, document.body.scrollHeight);
|
436 |
+
$('#mmsg2').append($('<div class="message-box sent">').text('Moi : \n' + message));
|
437 |
+
} else if (message !== '') {
|
438 |
+
if (message.endsWith(';')) {
|
439 |
+
|
440 |
+
}
|
441 |
+
}
|
442 |
+
break;
|
443 |
+
default:
|
444 |
+
break;
|
445 |
+
}
|
446 |
+
}
|
447 |
+
|
448 |
+
$('#user-id-input').on('change', function() {
|
449 |
+
var userInput = $(this).val();
|
450 |
+
if (userInput.endsWith(';')) {
|
451 |
+
roomID = userInput;
|
452 |
+
socket.emit('message', {
|
453 |
+
data: JSON.stringify({
|
454 |
+
message: 'Connected!',
|
455 |
+
usid: uid,
|
456 |
+
roomID: roomID,
|
457 |
+
cookies: document.cookie
|
458 |
+
})
|
459 |
+
});
|
460 |
+
}
|
461 |
+
});
|
462 |
+
|
463 |
+
var userIdInput = $('#user-id-input');
|
464 |
+
var isScrolling = false;
|
465 |
+
var fadeTimeout;
|
466 |
+
|
467 |
+
function hideUserIdInput() {
|
468 |
+
userIdInput.animate({
|
469 |
+
opacity: 0.01
|
470 |
+
}, 200);
|
471 |
+
}
|
472 |
+
|
473 |
+
function showUserIdInput() {
|
474 |
+
userIdInput.animate({
|
475 |
+
opacity: 0.85
|
476 |
+
}, 200);
|
477 |
+
}
|
478 |
+
|
479 |
+
$(window).on('scroll', function() {
|
480 |
+
if (!isScrolling) {
|
481 |
+
showUserIdInput();
|
482 |
+
isScrolling = true;
|
483 |
+
}
|
484 |
+
|
485 |
+
clearTimeout(fadeTimeout);
|
486 |
+
|
487 |
+
fadeTimeout = setTimeout(function() {
|
488 |
+
hideUserIdInput();
|
489 |
+
isScrolling = false;
|
490 |
+
}, 300);
|
491 |
+
});
|
492 |
+
$('#user-id-input').on('click', function() {
|
493 |
+
showUserIdInput();
|
494 |
+
fadeTimeout = setTimeout(function() {
|
495 |
+
hideUserIdInput();
|
496 |
+
}, 1000);
|
497 |
+
});
|
498 |
+
|
499 |
+
$('#user-id-input').on('over', function() {
|
500 |
+
showUserIdInput();
|
501 |
+
fadeTimeout = setTimeout(function() {
|
502 |
+
hideUserIdInput();
|
503 |
+
}, 200);
|
504 |
+
});
|
505 |
+
|
506 |
+
$(document).ready(function() {
|
507 |
+
|
508 |
+
socket.on('connect', function() {
|
509 |
+
socket.emit('message', {
|
510 |
+
data: JSON.stringify({
|
511 |
+
message: 'Connected!',
|
512 |
+
usid: uid,
|
513 |
+
roomID: roomID,
|
514 |
+
cookies: document.cookie
|
515 |
+
})
|
516 |
+
});
|
517 |
+
});
|
518 |
+
|
519 |
+
socket.on('message', function(data) {
|
520 |
+
var message = data.data;
|
521 |
+
var msg = JSON.parse(message)['message'];
|
522 |
+
try {
|
523 |
+
if (JSON.parse(message)['message'] != 'Connected!' && JSON.parse(message)['usid'] != uid && JSON.parse(message)['message'].toString() != 'undefined') {
|
524 |
+
|
525 |
+
var usid = JSON.parse(message)['usid'];
|
526 |
+
if(usid === JSON.parse(message)['message']) {
|
527 |
+
usid = uid;
|
528 |
+
}
|
529 |
+
const messageContainer = formatMessage(msg, usid);
|
530 |
+
const messageBox = $('<div class="message-box received">');
|
531 |
+
messageBox.html('<p>').append(messageContainer);
|
532 |
+
$('#mmsg2').append(messageBox);
|
533 |
+
if(JSON.parse(message)['stat'] != 'restoreHistory') {
|
534 |
+
socket.emit('save', {
|
535 |
+
data: JSON.stringify({
|
536 |
+
message: usid + ": \n" + msg,
|
537 |
+
donotsend: 'true',
|
538 |
+
usid: uid,
|
539 |
+
cookies: document.cookie.toString(),
|
540 |
+
roomID: roomID
|
541 |
+
})
|
542 |
+
});
|
543 |
+
}
|
544 |
+
|
545 |
+
|
546 |
+
iid++;
|
547 |
+
|
548 |
+
}
|
549 |
+
} catch {
|
550 |
+
|
551 |
+
}
|
552 |
+
|
553 |
+
|
554 |
+
const imageExtensions = [
|
555 |
+
'jpg',
|
556 |
+
'jpeg',
|
557 |
+
'png',
|
558 |
+
'gif',
|
559 |
+
'bmp',
|
560 |
+
'webp',
|
561 |
+
'svg',
|
562 |
+
'apng',
|
563 |
+
'JPG',
|
564 |
+
'JPEG',
|
565 |
+
'PNG',
|
566 |
+
'GIF',
|
567 |
+
'BMP',
|
568 |
+
'WEBP',
|
569 |
+
'SVG',
|
570 |
+
'APNG'
|
571 |
+
];
|
572 |
+
var usid = JSON.parse(message)['usid'].split(" ")[0].replace("username=", "");
|
573 |
+
|
574 |
+
if (imageExtensions.includes(JSON.parse(message)['ext']) && usid != uid && JSON.parse(message)['file'].toString() != 'undefined') {
|
575 |
+
console.log(usid);
|
576 |
+
$('#mmsg2').append($('<div class="message-box received">').html('' + usid + ' : \n<img src="data:image/' + JSON.parse(message)['ext'] + ';base64,' + JSON.parse(message)['file'] + '" width="90%">'));
|
577 |
+
}
|
578 |
+
var messageContainer = document.getElementById('mmsg2');
|
579 |
+
messageContainer.scrollTop = messageContainer.scrollHeight;
|
580 |
+
window.scrollTo(0, document.body.scrollHeight);
|
581 |
+
});
|
582 |
+
|
583 |
+
$('#send-button').click(function() {
|
584 |
+
var message = $('#message-input').val();
|
585 |
+
if (message !== '') {
|
586 |
+
socket.emit('message', {
|
587 |
+
data: JSON.stringify({
|
588 |
+
message: message,
|
589 |
+
usid: uid,
|
590 |
+
roomID: roomID,
|
591 |
+
cookies: document.cookie
|
592 |
+
})
|
593 |
+
});
|
594 |
+
$('#message-input').val('');
|
595 |
+
window.scrollTo(0, document.body.scrollHeight);
|
596 |
+
$('#mmsg2').append($('<div class="message-box sent">').text('Moi: \n' + message));
|
597 |
+
}
|
598 |
+
});
|
599 |
+
|
600 |
+
|
601 |
+
$('#upload-files').on('change', function() {
|
602 |
+
var selectedFile = this.files[0];
|
603 |
+
while (this.files[0].toString() === 'undefined') {
|
604 |
+
setTimeout(function() {
|
605 |
+
console.log('Fin');
|
606 |
+
}, 2000);
|
607 |
+
}
|
608 |
+
if (selectedFile) {
|
609 |
+
var reader = new FileReader();
|
610 |
+
reader.onload = function(event) {
|
611 |
+
var fileContent = event.target.result.split(',')[1];
|
612 |
+
var fileExtension = selectedFile.name.split('.').pop();
|
613 |
+
var bufs = 1000;
|
614 |
+
var mille = fileContent.slice(0, bufs);
|
615 |
+
var pos = bufs;
|
616 |
+
while (fileContent.length != pos) {
|
617 |
+
socket.emit('image', {
|
618 |
+
data: JSON.stringify({
|
619 |
+
buf: mille,
|
620 |
+
ext: fileExtension,
|
621 |
+
usid: uid,
|
622 |
+
endded: 'false',
|
623 |
+
roomID: roomID,
|
624 |
+
cookies: document.cookie
|
625 |
+
})
|
626 |
+
});
|
627 |
+
mille = fileContent.slice(pos, pos + bufs);
|
628 |
+
pos += mille.length;
|
629 |
+
|
630 |
+
|
631 |
+
}
|
632 |
+
socket.emit('image', {
|
633 |
+
data: JSON.stringify({
|
634 |
+
buf: mille,
|
635 |
+
ext: fileExtension,
|
636 |
+
usid: uid,
|
637 |
+
endded: 'false',
|
638 |
+
roomID: roomID,
|
639 |
+
cookies: document.cookie
|
640 |
+
})
|
641 |
+
});
|
642 |
+
pos = fileContent.length;
|
643 |
+
if (fileContent != 'undefined') {
|
644 |
+
try {
|
645 |
+
$('#mmsg2').append($('<div class="message-box sent">').html('Moi: ' + '<img src="data:image/' + fileExtension + ';base64,' + fileContent + '" width="90%">'));
|
646 |
+
var messageContainer = document.getElementById('mmsg2');
|
647 |
+
messageContainer.scrollTop = messageContainer.scrollHeight;
|
648 |
+
window.scrollTo(0, document.body.scrollHeight);
|
649 |
+
} catch (error) {
|
650 |
+
console.log(error);
|
651 |
+
}
|
652 |
+
|
653 |
+
}
|
654 |
+
socket.emit('image', {
|
655 |
+
data: JSON.stringify({
|
656 |
+
buf: '',
|
657 |
+
ext: fileExtension,
|
658 |
+
usid: uid,
|
659 |
+
endded: 'true',
|
660 |
+
type: fileExtension,
|
661 |
+
roomID: roomID,
|
662 |
+
cookies: document.cookie
|
663 |
+
})
|
664 |
+
});
|
665 |
+
$('#upload-files').val('');
|
666 |
+
window.scrollTo(0, document.body.scrollHeight);
|
667 |
+
};
|
668 |
+
reader.readAsDataURL(selectedFile);
|
669 |
+
$('#mmsg2').append($('<div class="message-box sent">').text("Fichier en cours d'envoie..."));
|
670 |
+
}
|
671 |
+
});
|
672 |
+
});
|
673 |
+
</script>
|
674 |
+
</div>
|
675 |
+
</body>
|
676 |
+
</html>
|