diff --git a/templates/index.html b/templates/index.html index 285ab86..3f40f96 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'); @@ -1521,9 +1521,10 @@ function addMessageToolbar(msgDiv) { copyBtn.title = 'Copy response'; copyBtn.onclick = () => { const t = getText(); + const done = () => { copyBtn.textContent = '✓'; setTimeout(() => copyBtn.innerHTML = '📋', 1500); showToast('Copied'); }; if (navigator.clipboard) { - 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'); } + navigator.clipboard.writeText(t).then(done).catch(() => { execCopy(t); done(); }); + } else { execCopy(t); done(); } }; const printBtn = document.createElement('button'); @@ -1591,6 +1592,16 @@ function scrollToTop() { if (c) c.scrollTop = 0; } function resetScrollLock() { _userScrolledAway = false; } +function execCopy(text) { + const ta = document.createElement('textarea'); + ta.value = text; + ta.style.position = 'fixed'; + ta.style.opacity = '0'; + document.body.appendChild(ta); + ta.select(); + document.execCommand('copy'); + document.body.removeChild(ta); +} function showToast(msg) { const el = document.createElement('div'); el.className = 'toast-error';