From 98b51c077553462dfe79e8a4a09b5dc00a111f97 Mon Sep 17 00:00:00 2001 From: gramps Date: Mon, 13 Jul 2026 16:12:17 -0700 Subject: [PATCH] fix: clipboard fallback for HTTP, response copy toast now works --- templates/index.html | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/index.html b/templates/index.html index 310af58..285ab86 100644 --- a/templates/index.html +++ b/templates/index.html @@ -1447,7 +1447,7 @@ function appendMessage(role, content, animate, isSearch = false, afterEl = null) const ms = now.getMilliseconds(); const timeStr = months[now.getMonth()] + ' ' + String(now.getDate()).padStart(2,'0') + ', ' + now.getFullYear() + ' ' + String(now.getHours()).padStart(2,'0') + ':' + String(now.getMinutes()).padStart(2,'0') + ':' + String(now.getSeconds()).padStart(2,'0') + '.' + String(Math.floor(ms / 10)).padStart(2,'0'); const textHtml = content ? renderMarkdown(content) : ''; - const copyIcon = role === 'user' && content ? `📋` : ''; + const copyIcon = role === 'user' && content ? `📋` : ''; div.innerHTML = `
${role === 'user' ? 'YOU' : 'AI'}
${role}${role === 'user' ? ' ' + timeStr + '' : ''}
${textHtml}${copyIcon}
${role === 'assistant' ? '
' : ''}
`; if (role === 'user') { const pair = document.createElement('div'); @@ -1522,8 +1522,8 @@ function addMessageToolbar(msgDiv) { copyBtn.onclick = () => { const t = getText(); if (navigator.clipboard) { - navigator.clipboard.writeText(t).then(() => { copyBtn.textContent = '✓'; showToast('Copied'); setTimeout(() => copyBtn.innerHTML = '📋', 1500); }); - } + navigator.clipboard.writeText(t).then(() => { copyBtn.textContent = '✓'; setTimeout(() => copyBtn.innerHTML = '📋', 1500); showToast('Copied'); }).catch(() => { fallbackCopy(t, copyBtn); showToast('Copied'); }); + } else { fallbackCopy(t, copyBtn); showToast('Copied'); } }; const printBtn = document.createElement('button'); @@ -1607,8 +1607,8 @@ function fallbackCopy(text, btn) { ta.select(); document.execCommand('copy'); document.body.removeChild(ta); - btn.textContent = 'copied!'; - setTimeout(() => btn.textContent = 'copy', 1500); + if (btn) btn.textContent = 'copied!'; + if (btn) setTimeout(() => btn.textContent = 'copy', 1500); } const userInput = document.getElementById('userInput');