DmitrMakeev commited on
Commit
20b3cf8
·
verified ·
1 Parent(s): 0461f08

Update chat.html

Browse files
Files changed (1) hide show
  1. chat.html +67 -0
chat.html CHANGED
@@ -266,6 +266,73 @@ function renderMessages(msgs, clear = true) {
266
  }
267
 
268
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
269
  setInterval(loadNewMessages, 2000);
270
  loadMessages();
271
  </script>
 
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
+ function decryptExistingMessages(key) {
295
+ if (!key) return; // ключ пустой — ничего не делаем
296
+
297
+ const messages = document.querySelectorAll('.message');
298
+ messages.forEach(msg => {
299
+ const cipher = msg.dataset.cipher; // зашифрованный текст
300
+ if (!cipher) return;
301
+
302
+ try {
303
+ // расшифровка через CryptoJS
304
+ const dec = CryptoJS.AES.decrypt(cipher, key).toString(CryptoJS.enc.Utf8);
305
+ if (dec) {
306
+ msg.querySelector('.message-text').textContent = dec;
307
+ }
308
+ } catch (e) {
309
+ // если ключ неправильный — оставляем "[🔒 Зашифровано]"
310
+ }
311
+ });
312
+ }
313
+
314
+ // пример использования при вводе ключа
315
+ const keyInput = document.getElementById('key-input');
316
+ keyInput.addEventListener('input', () => {
317
+ const key = keyInput.value.trim();
318
+ decryptExistingMessages(key);
319
+ });
320
+
321
+
322
+
323
+
324
+
325
+
326
+
327
+
328
+
329
+
330
+
331
+
332
+
333
+
334
+
335
+
336
  setInterval(loadNewMessages, 2000);
337
  loadMessages();
338
  </script>