diff --git a/source/javascripts/app/_copy.js b/source/javascripts/app/_copy.js index 4dfbbb6c0..16c7c1f5f 100644 --- a/source/javascripts/app/_copy.js +++ b/source/javascripts/app/_copy.js @@ -1,10 +1,24 @@ function copyToClipboard(container) { - const el = document.createElement('textarea'); - el.value = container.textContent.replace(/\n$/, ''); - document.body.appendChild(el); - el.select(); - document.execCommand('copy'); - document.body.removeChild(el); + const text = container.textContent.replace(/\n$/, ''); + + // Use the Clipboard API + navigator.clipboard.writeText(text) + .then(() => { + // Add success feedback + const button = container.parentNode.querySelector('.copy-clipboard'); + const originalHTML = button.innerHTML; + + // Show success state + button.innerHTML = 'Copied!'; + + // Reset after 1 second + setTimeout(() => { + button.innerHTML = originalHTML; + }, 1000); + }) + .catch(err => { + console.error('Failed to copy: ', err); + }); } function setupCodeCopy() {