feat: slide-out toast notification on copy icon clicks
This commit is contained in:
@@ -1436,7 +1436,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" onclick="event.stopPropagation();navigator.clipboard.writeText(${JSON.stringify(content)}).then(()=>{this.textContent='✓';setTimeout(()=>this.innerHTML='📋',1500)})">📋</span>` : '';
|
||||
const copyIcon = role === 'user' && content ? `<span class="user-copy-btn" onclick="event.stopPropagation();navigator.clipboard.writeText(${JSON.stringify(content)}).then(()=>{this.textContent='✓';showToast('Copied');setTimeout(()=>this.innerHTML='📋',1500)})">📋</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');
|
||||
@@ -1511,7 +1511,7 @@ function addMessageToolbar(msgDiv) {
|
||||
copyBtn.onclick = () => {
|
||||
const t = getText();
|
||||
if (navigator.clipboard) {
|
||||
navigator.clipboard.writeText(t).then(() => { copyBtn.textContent = '✓'; setTimeout(() => copyBtn.innerHTML = '📋', 1500); });
|
||||
navigator.clipboard.writeText(t).then(() => { copyBtn.textContent = '✓'; showToast('Copied'); setTimeout(() => copyBtn.innerHTML = '📋', 1500); });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1573,6 +1573,13 @@ function scrollToTop() {
|
||||
if (c) c.scrollTop = 0;
|
||||
}
|
||||
function resetScrollLock() { _userScrolledAway = false; }
|
||||
function showToast(msg) {
|
||||
const el = document.createElement('div');
|
||||
el.className = 'toast-error';
|
||||
el.textContent = msg;
|
||||
document.body.appendChild(el);
|
||||
setTimeout(() => el.remove(), 2000);
|
||||
}
|
||||
function fallbackCopy(text, btn) {
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = text;
|
||||
|
||||
Reference in New Issue
Block a user