fix: clipboard fallback for HTTP, response copy toast now works
This commit is contained in:
@@ -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 ? `<span class="user-copy-btn" data-content="${escapeHtml(content).replace(/"/g,'"')}" onclick="var el=this;event.stopPropagation();navigator.clipboard.writeText(el.getAttribute('data-content')).then(()=>{el.textContent='✓';showToast('Copied');setTimeout(()=>el.innerHTML='📋',1500)})">📋</span>` : '';
|
||||
const copyIcon = role === 'user' && content ? `<span class="user-copy-btn" data-content="${escapeHtml(content).replace(/"/g,'"')}" onclick="var el=this;event.stopPropagation();var t=el.getAttribute('data-content');if(navigator.clipboard){navigator.clipboard.writeText(t).then(function(){el.textContent='✓';setTimeout(function(){el.innerHTML='📋'},1500);showToast('Copied')}).catch(function(){fallbackCopy(t,null);showToast('Copied')})}else{fallbackCopy(t,null);showToast('Copied')}">📋</span>` : '';
|
||||
div.innerHTML = `<div class="avatar">${role === 'user' ? 'YOU' : 'AI'}</div><div class="content"><div class="role-label">${role}${role === 'user' ? ' <span class="msg-time">' + timeStr + '</span>' : ''}</div><div class="text">${textHtml}${copyIcon}</div>${role === 'assistant' ? '<div class="msg-toolbar"></div>' : ''}</div>`;
|
||||
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');
|
||||
|
||||
Reference in New Issue
Block a user