Mercurial Hosting > lang
view src/chat.js @ 5:a970b7a01a74
start ai
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 16 Jul 2025 15:08:14 -0600 |
parents | b1adec083e44 |
children | 025bb19b65b1 |
line wrap: on
line source
'use strict'; function openRenameChat(name) { let dialog = document.querySelector('dialog[rename]'); dialog.querySelector('input[name=name]').value = name; dialog.showModal(); } function renameChat() { ajax(`rename_chat.js?chat=${chatId}`); } function saveRenameChat() { let dialog = document.querySelector('dialog[rename]'); let name = dialog.querySelector('input[name=name]').value; ajax(`save_rename_chat.js?chat=${chatId}&name=${encodeURIComponent(name)}`); dialog.close(); } function deleteChat() { let dialog = document.querySelector('dialog[delete]'); dialog.showModal(); } function doDeleteChat(el) { closeModal(el); ajax(`delete_chat.js?chat=${chatId}`); } function showWaitingAiIcon() { document.querySelector('[waiting-ai-icon]').style.display = 'block'; } function hideWaitingAiIcon() { document.querySelector('[waiting-ai-icon]').style.display = 'none'; } function updateAi(html) { hideWaitingAiIcon(); document.querySelector('div[messages]').innerHTML = html; //handleMarkdown(); document.querySelector('textarea').focus(); /* let scroll = aiDialog.querySelector('[scroll]'); setTimeout(function(){ scroll.scrollTo(0,scroll.scrollHeight); }); */ } const isMobile = 'ontouchstart' in window || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0; function textareaKey(event) { if( event.keyCode===13 && !event.shiftKey && !event.ctrlKey && !isMobile ) { event.preventDefault(); askAi(); } } function fixTextarea(event) { let textarea = event.target; textarea.style.height = 'initial'; textarea.style.height = (textarea.scrollHeight+2) + 'px'; textarea.scrollIntoViewIfNeeded(false); } function askAi() { let input = document.querySelector('textarea'); let url = `ai_ask.js?chat=${chatId}&input=${encodeURIComponent(input.value)}`; ajax(url); input.value = ''; showWaitingAiIcon(); }