From 0bd13fb5536e203cefbb489407d1d009d964be8b Mon Sep 17 00:00:00 2001 From: Geetha <25wh5a0505@bvrithyderabad.edu.in> Date: Tue, 7 Jul 2026 18:15:56 +0530 Subject: [PATCH] feat: add copy-to-clipboard button on result card URL --- script.js | 50 +++++++++++++++++++++++++++++++++++++++++++++++++- style.css | 42 +++++++++++++++++++++++++++++++++++++++++- 2 files changed, 90 insertions(+), 2 deletions(-) diff --git a/script.js b/script.js index 2c902f0..c1600c3 100644 --- a/script.js +++ b/script.js @@ -144,14 +144,62 @@ function showResult(type, title, desc, url, threats) {
${title}
${desc}
- ${url ? `
${url}
` : ''} + ${url ? `
+ ${url} + +
` : ''} ${threats && threats.length ? `
${threats.map(t => `${t}`).join('')}
` : ''}
`; } +function copyResultUrl(btn) { + const textEl = btn.previousElementSibling; + const text = textEl ? textEl.textContent : ''; + if (!text) return; + const label = btn.querySelector('.copy-url-label'); + const markCopied = () => { + btn.classList.add('copied'); + if (label) label.textContent = 'Copied'; + clearTimeout(btn._copyResetTimer); + btn._copyResetTimer = setTimeout(() => { + btn.classList.remove('copied'); + if (label) label.textContent = 'Copy'; + }, 2000); + }; + + if (navigator.clipboard && navigator.clipboard.writeText) { + navigator.clipboard.writeText(text).then(markCopied).catch(() => { + fallbackCopy(text); + markCopied(); + }); + } else { + fallbackCopy(text); + markCopied(); + } +} + +function fallbackCopy(text) { + const textarea = document.createElement('textarea'); + textarea.value = text; + textarea.style.position = 'fixed'; + textarea.style.opacity = '0'; + document.body.appendChild(textarea); + textarea.select(); + try { document.execCommand('copy'); } catch (e) { /* no-op */ } + document.body.removeChild(textarea); +} async function checkSecurity() { const input = document.getElementById('urlInput'); const btn = document.getElementById('scanBtn'); diff --git a/style.css b/style.css index 49e1885..1864682 100644 --- a/style.css +++ b/style.css @@ -560,20 +560,60 @@ html.light-mode input[type="text"]:focus { color: var(--text-sub); line-height: 1.6; } - .result-url { margin-top: 10px; + display: flex; + align-items: center; + gap: 10px; font-family: 'Courier New', monospace; font-size: 11px; color: var(--text-muted); background: rgba(0,0,0,0.2); border-radius: 8px; padding: 8px 12px; +} + +.result-url-text { + flex: 1; word-break: break-all; } html.light-mode .result-url { background: rgba(0,0,0,0.06); } +.copy-url-btn { + flex-shrink: 0; + display: flex; + align-items: center; + gap: 5px; + background: rgba(0,245,255,0.1); + border: 1px solid rgba(0,245,255,0.25); + border-radius: 6px; + padding: 4px 9px; + color: var(--accent-cyan); + font-family: inherit; + font-size: 10px; + font-weight: 600; + text-transform: uppercase; + letter-spacing: 0.04em; + cursor: pointer; + transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease; +} + +.copy-url-btn:hover { + background: rgba(0,245,255,0.18); + border-color: var(--accent-cyan); +} + +.copy-url-btn .check-icon { display: none; } + +.copy-url-btn.copied { + background: rgba(0,255,136,0.14); + border-color: rgba(0,255,136,0.4); + color: var(--accent-green); +} + +.copy-url-btn.copied .copy-icon { display: none; } +.copy-url-btn.copied .check-icon { display: block; } .threat-tags { display: flex; flex-wrap: wrap;