From 566f97f177c18c6963b8a7de5950e7568d5ec83c Mon Sep 17 00:00:00 2001 From: GEgorov Date: Tue, 7 Oct 2025 00:55:15 +0300 Subject: [PATCH] modified: frontend/src/pages/ApiKeys.tsx --- frontend/src/pages/ApiKeys.tsx | 30 +++++++++++++++++++++++++++--- 1 file changed, 27 insertions(+), 3 deletions(-) diff --git a/frontend/src/pages/ApiKeys.tsx b/frontend/src/pages/ApiKeys.tsx index ceb9629..e2dca50 100644 --- a/frontend/src/pages/ApiKeys.tsx +++ b/frontend/src/pages/ApiKeys.tsx @@ -56,9 +56,33 @@ export default function ApiKeys() { }, }); - const copyToClipboard = (key: string) => { - navigator.clipboard.writeText(key); - toast.success('API ключ скопирован в буфер обмена'); + const copyToClipboard = async (key: string) => { + try { + // Try modern clipboard API first (requires HTTPS or localhost) + if (navigator.clipboard && window.isSecureContext) { + await navigator.clipboard.writeText(key); + toast.success('API ключ скопирован в буфер обмена'); + } else { + // Fallback for HTTP + const textArea = document.createElement('textarea'); + textArea.value = key; + textArea.style.position = 'fixed'; + textArea.style.left = '-999999px'; + textArea.style.top = '-999999px'; + document.body.appendChild(textArea); + textArea.focus(); + textArea.select(); + try { + document.execCommand('copy'); + toast.success('API ключ скопирован в буфер обмена'); + } catch (err) { + toast.error('Не удалось скопировать'); + } + textArea.remove(); + } + } catch (err) { + toast.error('Не удалось скопировать'); + } }; const toggleReveal = (id: string) => {