4
|
1 'use strict';
|
|
2
|
|
3 function openRenameChat(name) {
|
|
4 let dialog = document.querySelector('dialog[rename]');
|
|
5 dialog.querySelector('input[name=name]').value = name;
|
|
6 dialog.showModal();
|
|
7 }
|
|
8
|
|
9 function renameChat() {
|
|
10 ajax(`rename_chat.js?chat=${chatId}`);
|
|
11 }
|
|
12
|
|
13 function saveRenameChat() {
|
|
14 let dialog = document.querySelector('dialog[rename]');
|
|
15 let name = dialog.querySelector('input[name=name]').value;
|
|
16 ajax(`save_rename_chat.js?chat=${chatId}&name=${encodeURIComponent(name)}`);
|
|
17 dialog.close();
|
|
18 }
|
|
19
|
|
20 function deleteChat() {
|
|
21 let dialog = document.querySelector('dialog[delete]');
|
|
22 dialog.showModal();
|
|
23 }
|
|
24
|
|
25 function doDeleteChat(el) {
|
|
26 closeModal(el);
|
|
27 ajax(`delete_chat.js?chat=${chatId}`);
|
|
28 }
|
|
29
|
|
30 function showWaitingAiIcon() {
|
|
31 document.querySelector('[waiting-ai-icon]').style.display = 'block';
|
|
32 }
|
|
33
|
|
34 const isMobile = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
|
|
35
|
|
36 function textareaKey(event) {
|
|
37 if( event.keyCode===13 && !event.shiftKey && !event.ctrlKey && !isMobile ) {
|
|
38 event.preventDefault();
|
|
39 askAi();
|
|
40 }
|
|
41 }
|
|
42
|
|
43 function fixTextarea(event) {
|
|
44 let textarea = event.target;
|
|
45 textarea.style.height = 'initial';
|
|
46 textarea.style.height = (textarea.scrollHeight+2) + 'px';
|
|
47 textarea.scrollIntoViewIfNeeded(false);
|
|
48 }
|
|
49
|
|
50 function askAi() {
|
|
51 let input = document.querySelector('textarea');
|
|
52 let url = `ai_ask.js?key=${chatId}&input=${encodeURIComponent(input.value)}`;
|
|
53 ajax(url);
|
|
54 input.value = '';
|
|
55 showWaitingAiIcon();
|
|
56 }
|