From 87f9f4a7d8238259bcdac7763f546a489d8c7463 Mon Sep 17 00:00:00 2001 From: hubian <908234780@qq.com> Date: Sun, 12 Apr 2026 22:23:10 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A4=8D=E5=88=B6=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E4=BF=AE=E5=A4=8D=20-=20=E4=BD=BF=E7=94=A8=E9=9A=90=E8=97=8Fin?= =?UTF-8?q?put=E5=AD=98=E5=82=A8=E5=8E=9F=E5=A7=8B=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- templates/index.html | 50 ++++++++++++++++++++++++++++++-------------- 1 file changed, 34 insertions(+), 16 deletions(-) diff --git a/templates/index.html b/templates/index.html index 2741134..7138a42 100644 --- a/templates/index.html +++ b/templates/index.html @@ -249,9 +249,6 @@ div.className = `message ${role}`; const avatar = role === 'user' ? '👤' : '🤖'; - // 准备复制内容 - 转义双引号用于HTML属性 - const contentForCopy = content.replace(/&/g, '&').replace(/"/g, '"'); - let html = `
${avatar}
`; // 思考内容 @@ -272,8 +269,9 @@ } else { html += `
${escapeHtml(content)}
`; } - // 复制按钮 - html += ``; + // 复制按钮 - 使用隐藏input存储原始内容 + html += ``; + html += ``; html += `
`; // Agent信息 @@ -301,19 +299,39 @@ } function copyMessage(btn) { - // 获取存储的内容并解码HTML实体 - let text = btn.dataset.content || ''; - // 解码HTML实体 - text = text.replace(/&/g, '&').replace(/"/g, '"').replace(/</g, '<').replace(/>/g, '>').replace(/'/g, "'"); + // 从隐藏input获取原始内容 + const hiddenInput = btn.parentElement.querySelector('.copy-source'); + if (!hiddenInput) { + console.error('找不到复制源'); + return; + } + const text = hiddenInput.value; - navigator.clipboard.writeText(text).then(() => { - btn.innerHTML = ' 已复制'; - btn.classList.add('copied'); - setTimeout(() => { btn.innerHTML = ' 复制'; btn.classList.remove('copied'); }, 2000); - }).catch(err => { + // 创建临时textarea复制 + const textarea = document.createElement('textarea'); + textarea.value = text; + textarea.style.position = 'fixed'; + textarea.style.left = '-9999px'; + document.body.appendChild(textarea); + textarea.select(); + + try { + const success = document.execCommand('copy'); + if (success) { + btn.innerHTML = ' 已复制'; + btn.classList.add('copied'); + setTimeout(() => { + btn.innerHTML = ' 复制'; + btn.classList.remove('copied'); + }, 2000); + } else { + btn.innerHTML = ' 失败'; + } + } catch (err) { console.error('复制失败:', err); - btn.innerHTML = ' 失败'; - }); + } + + document.body.removeChild(textarea); } function escapeHtml(text) {