Update index.html
Browse files- index.html +10 -4
index.html
CHANGED
|
@@ -659,6 +659,7 @@
|
|
| 659 |
'modal.apply': '套用',
|
| 660 |
'message.copy': '複製',
|
| 661 |
'message.regenerate': '重生',
|
|
|
|
| 662 |
'toast.copied': '已複製',
|
| 663 |
'toast.exported': '已導出 Markdown',
|
| 664 |
'toast.exportedAll': '已導出所有資料',
|
|
@@ -740,6 +741,7 @@
|
|
| 740 |
'modal.apply': 'Apply',
|
| 741 |
'message.copy': 'Copy',
|
| 742 |
'message.regenerate': 'Regenerate',
|
|
|
|
| 743 |
'toast.copied': 'Copied',
|
| 744 |
'toast.exported': 'Markdown exported',
|
| 745 |
'toast.exportedAll': 'All data exported',
|
|
@@ -1191,6 +1193,7 @@
|
|
| 1191 |
|
| 1192 |
function regenerateMessage(idx) {
|
| 1193 |
if (!state.currentChatId) return;
|
|
|
|
| 1194 |
const chat = state.chats.find(c => c.id === state.currentChatId);
|
| 1195 |
if (!chat) return;
|
| 1196 |
// Remove this and all subsequent messages
|
|
@@ -1260,6 +1263,7 @@
|
|
| 1260 |
// ============ API Calls ============
|
| 1261 |
async function sendMessage(content, isRegenerate = false) {
|
| 1262 |
if (!state.currentProviderId) return;
|
|
|
|
| 1263 |
const provider = state.providers.find(p => p.id === state.currentProviderId);
|
| 1264 |
if (!provider) return;
|
| 1265 |
|
|
@@ -1369,13 +1373,12 @@
|
|
| 1369 |
|
| 1370 |
function updateSendButton() {
|
| 1371 |
const hasText = els.messageInput && els.messageInput.value.trim().length > 0;
|
| 1372 |
-
|
|
|
|
| 1373 |
if (state.isStreaming && els.sendBtn) {
|
| 1374 |
els.sendBtn.innerHTML = '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><rect x="6" y="4" width="4" height="16"></rect><rect x="14" y="4" width="4" height="16"></rect></svg>';
|
| 1375 |
-
els.sendBtn.onclick = stopGeneration;
|
| 1376 |
} else if (els.sendBtn) {
|
| 1377 |
els.sendBtn.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"></line><polygon points="22 2 15 22 11 13 2 9 22 2"></polygon></svg>';
|
| 1378 |
-
els.sendBtn.onclick = () => { if (els.messageInput) sendMessage(els.messageInput.value.trim()); };
|
| 1379 |
}
|
| 1380 |
}
|
| 1381 |
|
|
@@ -1510,7 +1513,10 @@
|
|
| 1510 |
}
|
| 1511 |
});
|
| 1512 |
}
|
| 1513 |
-
if (els.sendBtn) els.sendBtn.addEventListener('click', () => {
|
|
|
|
|
|
|
|
|
|
| 1514 |
if (els.exportChatBtn) els.exportChatBtn.addEventListener('click', () => {
|
| 1515 |
const chat = state.chats.find(c => c.id === state.currentChatId);
|
| 1516 |
if (chat) exportChatMarkdown(chat);
|
|
|
|
| 659 |
'modal.apply': '套用',
|
| 660 |
'message.copy': '複製',
|
| 661 |
'message.regenerate': '重生',
|
| 662 |
+
'toast.streaming': '正在生成中,請先停止',
|
| 663 |
'toast.copied': '已複製',
|
| 664 |
'toast.exported': '已導出 Markdown',
|
| 665 |
'toast.exportedAll': '已導出所有資料',
|
|
|
|
| 741 |
'modal.apply': 'Apply',
|
| 742 |
'message.copy': 'Copy',
|
| 743 |
'message.regenerate': 'Regenerate',
|
| 744 |
+
'toast.streaming': 'Generation in progress, please stop first',
|
| 745 |
'toast.copied': 'Copied',
|
| 746 |
'toast.exported': 'Markdown exported',
|
| 747 |
'toast.exportedAll': 'All data exported',
|
|
|
|
| 1193 |
|
| 1194 |
function regenerateMessage(idx) {
|
| 1195 |
if (!state.currentChatId) return;
|
| 1196 |
+
if (state.isStreaming) { showToast(t('toast.streaming'), 'info'); return; }
|
| 1197 |
const chat = state.chats.find(c => c.id === state.currentChatId);
|
| 1198 |
if (!chat) return;
|
| 1199 |
// Remove this and all subsequent messages
|
|
|
|
| 1263 |
// ============ API Calls ============
|
| 1264 |
async function sendMessage(content, isRegenerate = false) {
|
| 1265 |
if (!state.currentProviderId) return;
|
| 1266 |
+
if (!isRegenerate && state.isStreaming) return; // guard: never double-send
|
| 1267 |
const provider = state.providers.find(p => p.id === state.currentProviderId);
|
| 1268 |
if (!provider) return;
|
| 1269 |
|
|
|
|
| 1373 |
|
| 1374 |
function updateSendButton() {
|
| 1375 |
const hasText = els.messageInput && els.messageInput.value.trim().length > 0;
|
| 1376 |
+
// While streaming the button acts as STOP, so it must stay enabled
|
| 1377 |
+
if (els.sendBtn) els.sendBtn.disabled = state.isStreaming ? false : (!state.currentProviderId || !hasText);
|
| 1378 |
if (state.isStreaming && els.sendBtn) {
|
| 1379 |
els.sendBtn.innerHTML = '<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5"><rect x="6" y="4" width="4" height="16"></rect><rect x="14" y="4" width="4" height="16"></rect></svg>';
|
|
|
|
| 1380 |
} else if (els.sendBtn) {
|
| 1381 |
els.sendBtn.innerHTML = '<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"></line><polygon points="22 2 15 22 11 13 2 9 22 2"></polygon></svg>';
|
|
|
|
| 1382 |
}
|
| 1383 |
}
|
| 1384 |
|
|
|
|
| 1513 |
}
|
| 1514 |
});
|
| 1515 |
}
|
| 1516 |
+
if (els.sendBtn) els.sendBtn.addEventListener('click', () => {
|
| 1517 |
+
if (state.isStreaming) { stopGeneration(); return; }
|
| 1518 |
+
if (els.messageInput) { const text = els.messageInput.value.trim(); if (text) sendMessage(text); }
|
| 1519 |
+
});
|
| 1520 |
if (els.exportChatBtn) els.exportChatBtn.addEventListener('click', () => {
|
| 1521 |
const chat = state.chats.find(c => c.id === state.currentChatId);
|
| 1522 |
if (chat) exportChatMarkdown(chat);
|