diff --git a/templates/index.html b/templates/index.html index 9696b79..2741134 100644 --- a/templates/index.html +++ b/templates/index.html @@ -249,6 +249,9 @@ div.className = `message ${role}`; const avatar = role === 'user' ? '👤' : '🤖'; + // 准备复制内容 - 转义双引号用于HTML属性 + const contentForCopy = content.replace(/&/g, '&').replace(/"/g, '"'); + let html = `
${avatar}
`; // 思考内容 @@ -265,14 +268,12 @@ // 消息内容 html += `
`; if (role === 'assistant') { - // AI消息用Markdown渲染 html += `
${marked.parse(content)}
`; } else { - // 用户消息普通显示 html += `
${escapeHtml(content)}
`; } // 复制按钮 - html += ``; + html += ``; html += `
`; // Agent信息 @@ -299,11 +300,19 @@ } } - function copyMessage(btn, text) { + function copyMessage(btn) { + // 获取存储的内容并解码HTML实体 + let text = btn.dataset.content || ''; + // 解码HTML实体 + text = text.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, "'"); + navigator.clipboard.writeText(text).then(() => { btn.innerHTML = ' 已复制'; btn.classList.add('copied'); setTimeout(() => { btn.innerHTML = ' 复制'; btn.classList.remove('copied'); }, 2000); + }).catch(err => { + console.error('复制失败:', err); + btn.innerHTML = ' 失败'; }); }