v2.1版本无法复制问题
将根目录下js文件120-127行代码改为
function copyServerIP() {
const ip = document.getElementById(‘server-ip’)?.textContent;
if (!ip) return;
const input = document.createElement(‘input’);
input.value = ip;
document.body.appendChild(input);
input.select();
input.setSelectionRange(0, 99999);
document.execCommand(‘copy’);
document.body.removeChild(input);
}
502-511行代码改为
document.querySelectorAll(‘.copy-btn’).forEach(btn => {
btn.addEventListener(‘click’, async () => {
const ip = state.serverIP;
if (!ip) return;
const originalHTML = btn.innerHTML;
btn.disabled = true;
try {
// 优先使用现代 API
if (navigator.clipboard && navigator.clipboard.writeText) {
await navigator.clipboard.writeText(ip);
} else {
// HTTP / 老设备兜底
const ta = document.createElement(‘textarea’);
ta.value = ip;
ta.style.cssText = ‘position:fixed;opacity:0’;
document.body.appendChild(ta);
ta.select();
document.execCommand(‘copy’);
document.body.removeChild(ta);
}
// 成功态
btn.innerHTML = `
<path d=“M20 6L9 17L4 12”
stroke=“currentColor”
stroke-width=“2”
stroke-linecap=“round”
stroke-linejoin=“round”/>
`;
setTimeout(() => {
btn.innerHTML = originalHTML;
btn.disabled = false;
}, 2000);
} catch {
btn.disabled = false;
}
});
});
完美解决复制问题