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
|
9
|
30 function systemPrompt() {
|
|
31 let dialog = document.querySelector('dialog[system_prompt]');
|
|
32 dialog.showModal();
|
|
33 }
|
|
34
|
4
|
35 function showWaitingAiIcon() {
|
|
36 document.querySelector('[waiting-ai-icon]').style.display = 'block';
|
|
37 }
|
|
38
|
5
|
39 function hideWaitingAiIcon() {
|
|
40 document.querySelector('[waiting-ai-icon]').style.display = 'none';
|
|
41 }
|
|
42
|
|
43 function updateAi(html) {
|
|
44 hideWaitingAiIcon();
|
|
45 document.querySelector('div[messages]').innerHTML = html;
|
6
|
46 handleMarkdown();
|
5
|
47 document.querySelector('textarea').focus();
|
6
|
48 window.scrollTo(0, document.body.scrollHeight);
|
5
|
49 /*
|
|
50 let scroll = aiDialog.querySelector('[scroll]');
|
|
51 setTimeout(function(){
|
|
52 scroll.scrollTo(0,scroll.scrollHeight);
|
|
53 });
|
|
54 */
|
12
|
55 let audios = document.querySelectorAll('audio');
|
|
56 if( audios.length >= 1 ) {
|
|
57 let audio = audios[audios.length-1];
|
|
58 audio.play();
|
|
59 }
|
5
|
60 }
|
|
61
|
4
|
62 const isMobile = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0;
|
|
63
|
|
64 function textareaKey(event) {
|
|
65 if( event.keyCode===13 && !event.shiftKey && !event.ctrlKey && !isMobile ) {
|
|
66 event.preventDefault();
|
|
67 askAi();
|
|
68 }
|
|
69 }
|
|
70
|
11
|
71 function fixTextarea(textarea) {
|
4
|
72 textarea.style.height = 'initial';
|
|
73 textarea.style.height = (textarea.scrollHeight+2) + 'px';
|
|
74 textarea.scrollIntoViewIfNeeded(false);
|
|
75 }
|
|
76
|
|
77 function askAi() {
|
|
78 let input = document.querySelector('textarea');
|
5
|
79 let url = `ai_ask.js?chat=${chatId}&input=${encodeURIComponent(input.value)}`;
|
4
|
80 ajax(url);
|
|
81 input.value = '';
|
11
|
82 fixTextarea(input);
|
4
|
83 showWaitingAiIcon();
|
|
84 }
|