Mercurial Hosting > lang
comparison src/chat.js @ 71:44bec62c49e2 default tip
split ask
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 24 Aug 2025 08:32:08 -0600 |
parents | f5e72f2d1025 |
children |
comparison
equal
deleted
inserted
replaced
70:4a73af8f2203 | 71:44bec62c49e2 |
---|---|
71 | 71 |
72 function scrollToEnd() { | 72 function scrollToEnd() { |
73 window.scrollTo(0, document.body.scrollHeight); | 73 window.scrollTo(0, document.body.scrollHeight); |
74 } | 74 } |
75 | 75 |
76 function updateAi(html) { | |
77 hideWaitingAiIcon(); | |
78 document.querySelector('div[messages]').insertAdjacentHTML('beforeend',html); | |
79 handleChatMarkdown(); | |
80 document.querySelector('textarea').focus(); | |
81 scrollToEnd(); | |
82 if( chat.autoplay ) | |
83 playLastMessage(); | |
84 } | |
85 | |
86 const isMobile = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0; | 76 const isMobile = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0; |
87 | 77 |
88 function textareaKey(event) { | 78 function textareaKey(event) { |
89 if( event.keyCode===13 && !event.shiftKey && !event.ctrlKey && !isMobile ) { | 79 if( event.keyCode===13 && !event.shiftKey && !event.ctrlKey && !isMobile ) { |
90 event.preventDefault(); | 80 event.preventDefault(); |
91 askAi(); | 81 askAi1(); |
92 } | 82 } |
93 } | 83 } |
94 | 84 |
95 let audio; | 85 let audio; |
96 | 86 |
100 if( !audio ) | 90 if( !audio ) |
101 audio = document.querySelector('div[buttons] audio'); | 91 audio = document.querySelector('div[buttons] audio'); |
102 audio.src = `/tts.mp3?voice=${chat.voice}&instructions=${encodeURIComponent(chat.tts_instructions)}&text=${encodeURIComponent(textarea.value)}`; | 92 audio.src = `/tts.mp3?voice=${chat.voice}&instructions=${encodeURIComponent(chat.tts_instructions)}&text=${encodeURIComponent(textarea.value)}`; |
103 } | 93 } |
104 | 94 |
105 function askAi() { | 95 function askAi1() { |
106 let input = document.querySelector('textarea'); | 96 let input = document.querySelector('textarea'); |
107 let url = `ai_ask.js?chat=${chat.id}&input=${encodeURIComponent(input.value)}`; | 97 let url = `ai_ask1.js?chat=${chat.id}&input=${encodeURIComponent(input.value)}`; |
108 ajax(url); | 98 ajax(url); |
109 input.value = ''; | 99 input.value = ''; |
110 fixChatTextarea(input); | 100 fixChatTextarea(input); |
101 } | |
102 | |
103 function askAi2(html) { | |
104 document.querySelector('div[messages]').insertAdjacentHTML('beforeend',html); | |
105 handleChatMarkdown(); | |
106 document.querySelector('textarea').focus(); | |
107 scrollToEnd(); | |
108 let url = `ai_ask2.js?chat=${chat.id}`; | |
109 ajax(url); | |
111 showWaitingAiIcon(); | 110 showWaitingAiIcon(); |
111 } | |
112 | |
113 function updateAi(html) { | |
114 hideWaitingAiIcon(); | |
115 document.querySelector('div[messages]').insertAdjacentHTML('beforeend',html); | |
116 handleChatMarkdown(); | |
117 document.querySelector('textarea').focus(); | |
118 scrollToEnd(); | |
119 if( chat.autoplay ) | |
120 playLastMessage(); | |
112 } | 121 } |
113 | 122 |
114 | 123 |
115 function setText(text) { | 124 function setText(text) { |
116 let textarea = document.querySelector('textarea'); | 125 let textarea = document.querySelector('textarea'); |