Mercurial Hosting > lang
comparison src/chat.js @ 29:505185272dd7
edit chat
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sat, 02 Aug 2025 22:39:48 -0600 |
parents | 99b71a377f2c |
children | 1e7d855afde3 |
comparison
equal
deleted
inserted
replaced
28:99b71a377f2c | 29:505185272dd7 |
---|---|
1 'use strict'; | 1 'use strict'; |
2 | 2 |
3 function openRenameChat(name) { | 3 let chat; |
4 let dialog = document.querySelector('dialog[rename]'); | 4 |
5 dialog.querySelector('input[name=name]').value = name; | 5 function setChat(newChat) { |
6 chat = newChat; | |
7 document.querySelector('[content] [name]').textContent = chat.name; | |
8 } | |
9 | |
10 function editChat(name) { | |
11 let dialog = document.querySelector('dialog[edit]'); | |
12 dialog.querySelector('input[name=name]').value = chat.name; | |
6 dialog.showModal(); | 13 dialog.showModal(); |
7 } | 14 } |
8 | 15 |
9 function renameChat() { | 16 function saveChat(form) { |
10 ajax(`rename_chat.js?chat=${chatId}`); | 17 closeModal(form); |
11 } | 18 ajaxForm('save_chat.js',form); |
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 } |
19 | 20 |
20 function deleteChat() { | 21 function deleteChat() { |
21 let dialog = document.querySelector('dialog[delete]'); | 22 let dialog = document.querySelector('dialog[delete]'); |
22 dialog.showModal(); | 23 dialog.showModal(); |
23 } | 24 } |
24 | 25 |
25 function doDeleteChat(el) { | 26 function doDeleteChat(el) { |
26 closeModal(el); | 27 closeModal(el); |
27 ajax(`delete_chat.js?chat=${chatId}`); | 28 ajax(`delete_chat.js?chat=${chat.id}`); |
28 } | 29 } |
29 | 30 |
30 function systemPrompt() { | 31 function systemPrompt() { |
31 let dialog = document.querySelector('dialog[system_prompt]'); | 32 let dialog = document.querySelector('dialog[system_prompt]'); |
32 dialog.showModal(); | 33 dialog.showModal(); |
46 let audio = audios[audios.length-1]; | 47 let audio = audios[audios.length-1]; |
47 audio.play(); | 48 audio.play(); |
48 } | 49 } |
49 } | 50 } |
50 | 51 |
52 function handleChatMarkdown() { | |
53 handleMarkdown(chat.language_region); | |
54 } | |
55 | |
51 function scrollToEnd() { | 56 function scrollToEnd() { |
52 window.scrollTo(0, document.body.scrollHeight); | 57 window.scrollTo(0, document.body.scrollHeight); |
53 } | 58 } |
54 | 59 |
55 function updateAi(html) { | 60 function updateAi(html) { |
56 hideWaitingAiIcon(); | 61 hideWaitingAiIcon(); |
57 document.querySelector('div[messages]').insertAdjacentHTML('beforeend',html); | 62 document.querySelector('div[messages]').insertAdjacentHTML('beforeend',html); |
58 handleMarkdown(); | 63 handleChatMarkdown(); |
59 document.querySelector('textarea').focus(); | 64 document.querySelector('textarea').focus(); |
60 scrollToEnd(); | 65 scrollToEnd(); |
61 playLastMessage(); | 66 playLastMessage(); |
62 } | 67 } |
63 | 68 |
76 textarea.style.height = 'initial'; | 81 textarea.style.height = 'initial'; |
77 textarea.style.height = (textarea.scrollHeight+2) + 'px'; | 82 textarea.style.height = (textarea.scrollHeight+2) + 'px'; |
78 textarea.parentNode.scrollIntoViewIfNeeded(false); | 83 textarea.parentNode.scrollIntoViewIfNeeded(false); |
79 if( !audio ) | 84 if( !audio ) |
80 audio = document.querySelector('div[buttons] audio'); | 85 audio = document.querySelector('div[buttons] audio'); |
81 audio.src = `/tts.mp3?lang=${lang}&text=${encodeURIComponent(textarea.value)}`; | 86 audio.src = `/tts.mp3?lang=${chat.language_region}&text=${encodeURIComponent(textarea.value)}`; |
82 } | 87 } |
83 | 88 |
84 function askAi() { | 89 function askAi() { |
85 let input = document.querySelector('textarea'); | 90 let input = document.querySelector('textarea'); |
86 let url = `ai_ask.js?chat=${chatId}&input=${encodeURIComponent(input.value)}`; | 91 let url = `ai_ask.js?chat=${chat.id}&input=${encodeURIComponent(input.value)}`; |
87 ajax(url); | 92 ajax(url); |
88 input.value = ''; | 93 input.value = ''; |
89 fixTextarea(input); | 94 fixTextarea(input); |
90 showWaitingAiIcon(); | 95 showWaitingAiIcon(); |
91 } | 96 } |