diff --git a/web/index.html b/web/index.html
index d38b7d9..80e8dbb 100644
--- a/web/index.html
+++ b/web/index.html
@@ -676,14 +676,47 @@
}
}
+ // 通用复制函数(兼容 HTTP 和 HTTPS)
+ function copyToClipboard(text) {
+ // 方法1: 尝试 navigator.clipboard (HTTPS)
+ if (navigator.clipboard && navigator.clipboard.writeText) {
+ return navigator.clipboard.writeText(text)
+ .then(() => true)
+ .catch(() => false);
+ }
+
+ // 方法2: 使用传统的 execCommand (HTTP 也可用)
+ return new Promise((resolve) => {
+ const textarea = document.createElement('textarea');
+ textarea.value = text;
+ textarea.style.position = 'fixed';
+ textarea.style.left = '-9999px';
+ textarea.style.top = '0';
+ document.body.appendChild(textarea);
+
+ try {
+ textarea.select();
+ textarea.setSelectionRange(0, 99999);
+ const success = document.execCommand('copy');
+ document.body.removeChild(textarea);
+ resolve(success);
+ } catch (err) {
+ document.body.removeChild(textarea);
+ resolve(false);
+ }
+ });
+ }
+
// 复制 JSON
function copyJSON() {
if (currentViewData) {
const text = JSON.stringify(currentViewData, null, 2);
- navigator.clipboard.writeText(text).then(() => {
- showToast('JSON 已复制到剪贴板');
- }).catch(() => {
- showToast('复制失败', 'error');
+ copyToClipboard(text).then((success) => {
+ if (success) {
+ showToast('JSON 已复制到剪贴板');
+ } else {
+ showToast('复制失败,请手动选择复制', 'error');
+ }
});
}
}
@@ -694,8 +727,12 @@
const response = await fetch(`/api/data/copy/${tag}`);
const data = await response.json();
- await navigator.clipboard.writeText(data.copy_text);
- showToast('配置已复制到剪贴板');
+ const success = await copyToClipboard(data.copy_text);
+ if (success) {
+ showToast('配置已复制到剪贴板');
+ } else {
+ showToast('复制失败,请手动选择复制', 'error');
+ }
} catch (error) {
showToast('复制失败:' + error.message, 'error');
}