|
5 | 5 | <title>DeepSeek Chat</title> |
6 | 6 | <link rel="stylesheet" href="/static/style.css"> |
7 | 7 | <script> |
8 | | - // Auto-scroll chat to bottom |
9 | | - window.onload = function() { |
| 8 | + function scrollChat() { |
10 | 9 | var chat = document.getElementById('chat-history'); |
11 | 10 | if (chat) chat.scrollTop = chat.scrollHeight; |
12 | | - document.getElementById('user_message').focus(); |
| 11 | + } |
| 12 | + function focusInput() { |
| 13 | + var input = document.getElementById('user_message'); |
| 14 | + if (input) input.focus(); |
| 15 | + } |
| 16 | + window.onload = function() { |
| 17 | + scrollChat(); |
| 18 | + focusInput(); |
13 | 19 | }; |
14 | | - // Enter to send, Shift+Enter for newline |
15 | 20 | function handleKey(e) { |
16 | 21 | if (e.key === 'Enter' && !e.shiftKey) { |
17 | 22 | e.preventDefault(); |
18 | | - document.getElementById('chat-form').submit(); |
| 23 | + sendChat(); |
19 | 24 | } |
20 | 25 | } |
| 26 | + function sendChat() { |
| 27 | + var btn = document.getElementById('send-btn'); |
| 28 | + var form = document.getElementById('chat-form'); |
| 29 | + var input = document.getElementById('user_message'); |
| 30 | + if (btn) btn.disabled = true; |
| 31 | + form.submit(); |
| 32 | + setTimeout(function() { if (input) input.value = ''; }, 100); |
| 33 | + } |
21 | 34 | </script> |
22 | 35 | </head> |
23 | 36 | <body> |
24 | 37 | <div class="container"> |
25 | 38 | <h1>DeepSeek Chat</h1> |
26 | | - <form id="chat-form" method="post" action="/chat" autocomplete="off"> |
27 | | - <textarea id="user_message" name="user_message" placeholder="Type your message..." required rows="2" onkeydown="handleKey(event)"></textarea> |
28 | | - <button type="submit">Send</button> |
| 39 | + <form id="chat-form" method="post" action="/chat" autocomplete="off" onsubmit="sendChat(); return false;"> |
| 40 | + <textarea id="user_message" name="user_message" placeholder="Type your message... (Enter to send, Shift+Enter for newline)" required rows="2" onkeydown="handleKey(event)"></textarea> |
| 41 | + <button id="send-btn" type="submit" {% if loading %}disabled{% endif %}>Send</button> |
29 | 42 | <button type="button" onclick="document.getElementById('reset-form').submit();" class="reset-btn">Reset</button> |
30 | 43 | </form> |
31 | 44 | <form id="reset-form" method="post" action="/reset" style="display:none;"></form> |
|
0 commit comments