diff --git a/index.html b/index.html index 40edfc1..e3b90c6 100644 --- a/index.html +++ b/index.html @@ -1075,17 +1075,33 @@ function copyQuestionPrompt(qId) { } } - navigator.clipboard.writeText(prompt).then(() => { - const btn = document.querySelector(`[data-copy="${qId}"]`); + const btn = document.querySelector(`[data-copy="${qId}"]`); + const showCopied = () => { if (btn) { btn.textContent = '✅ 已复制'; btn.classList.add('copied'); setTimeout(() => { btn.textContent = '📋 复制题目'; btn.classList.remove('copied'); }, 1500); } - }); + }; + + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(prompt).then(showCopied).catch(() => fallbackCopy(prompt, showCopied)); + } else { + fallbackCopy(prompt, showCopied); + } } // ─── Util ─── +function fallbackCopy(text, onSuccess) { + const ta = document.createElement('textarea'); + ta.value = text; + ta.style.cssText = 'position:fixed;left:-9999px;opacity:0'; + document.body.appendChild(ta); + ta.select(); + try { document.execCommand('copy'); onSuccess(); } catch (_) {} + document.body.removeChild(ta); +} + function escapeHtml(s) { if (!s) return ''; return s.replace(/&/g, '&').replace(//g, '>').replace(/"/g, '"');