diff --git a/web/admin.html b/web/admin.html index e40278c..1f422c1 100644 --- a/web/admin.html +++ b/web/admin.html @@ -686,8 +686,11 @@
-
+
${this.escapeHtml(prompt.text)}
+
@@ -1479,6 +1482,81 @@ this.showNotification(`❌ Test failed: ${error.message}`, 'error'); } } + + // Copy prompt to clipboard functionality + async copyPromptToClipboard(promptId) { + // Find the prompt text from the prompts array + const prompt = this.prompts.find(p => p.id === promptId); + if (!prompt) { + this.showNotification('❌ Prompt not found', 'error'); + return; + } + + const promptText = prompt.text; + + try { + // Use the modern Clipboard API if available + if (navigator.clipboard && window.isSecureContext) { + await navigator.clipboard.writeText(promptText); + this.showNotification('📋 Prompt copied to clipboard!', 'success'); + } else { + // Fallback for older browsers or non-secure contexts + const textArea = document.createElement('textarea'); + textArea.value = promptText; + textArea.style.position = 'fixed'; + textArea.style.left = '-999999px'; + textArea.style.top = '-999999px'; + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + + if (document.execCommand('copy')) { + this.showNotification('📋 Prompt copied to clipboard!', 'success'); + } else { + throw new Error('Copy command failed'); + } + + document.body.removeChild(textArea); + } + } catch (error) { + console.error('Copy to clipboard failed:', error); + this.showNotification('❌ Failed to copy prompt to clipboard', 'error'); + + // Show a fallback modal with the text for manual copying + this.showCopyFallbackModal(promptText); + } + } + + showCopyFallbackModal(text) { + // Create a temporary modal for manual copy + const modal = document.createElement('div'); + modal.className = 'fixed inset-0 bg-black bg-opacity-50 flex items-center justify-center z-50'; + modal.innerHTML = ` +
+

📋 Copy Prompt Text

+

Please manually copy the text below:

+ +
+ +
+
+ `; + document.body.appendChild(modal); + + // Auto-select the text in the textarea + const textarea = modal.querySelector('textarea'); + textarea.focus(); + textarea.select(); + + // Close modal when clicking outside + modal.addEventListener('click', (e) => { + if (e.target === modal) { + modal.remove(); + } + }); + } } // Initialize the admin interface