Compare commits

...

1 Commits

Author SHA1 Message Date
b97abb0fc6 fix: HTTP环境下复制功能修复 2026-04-26 11:18:27 +08:00
2 changed files with 27 additions and 10 deletions

View File

@@ -469,21 +469,38 @@ function deleteMessage(index) {
function copyMessage(index) {
if (!currentConversation) return;
const content = currentConversation.messages[index].content;
const msg = currentConversation.messages[index];
// 如果是图片消息,复制图片描述或提示
let content = msg.content;
if (msg.image && content === '[图片]') {
content = '[图片: ' + (msg.imageName || '未命名') + ']';
}
navigator.clipboard.writeText(content).then(() => {
showToast('已复制到剪贴板');
}).catch(err => {
// HTTP 环境下 navigator.clipboard 不工作,优先使用 fallback
try {
const textarea = document.createElement('textarea');
textarea.value = content;
textarea.style.position = 'fixed';
textarea.style.top = '0';
textarea.style.left = '0';
textarea.style.opacity = '0';
textarea.style.pointerEvents = 'none';
document.body.appendChild(textarea);
textarea.focus();
textarea.select();
document.execCommand('copy');
const success = document.execCommand('copy');
document.body.removeChild(textarea);
showToast('已复制到剪贴板');
});
if (success) {
showToast('已复制到剪贴板');
} else {
showToast('复制失败,请手动复制');
}
} catch (err) {
console.error('复制失败:', err);
showToast('复制失败,请手动复制');
}
}
// 清空当前对话

View File

@@ -8,12 +8,12 @@
<meta http-equiv="Pragma" content="no-cache">
<meta http-equiv="Expires" content="0">
<title>AI助手</title>
<link rel="stylesheet" href="style.css?v=2.1.1">
<link rel="stylesheet" href="style.css?v=2.1.2">
<link rel="manifest" href="manifest.json">
</head>
<body>
<div id="app"></div>
<script src="marked.min.js?v=2.1.1"></script>
<script src="app.js?v=2.1.1"></script>
<script src="marked.min.js?v=2.1.2"></script>
<script src="app.js?v=2.1.2"></script>
</body>
</html>