Fix copy token button to use execCommand for reliable copying

parent 64b18028
...@@ -200,28 +200,23 @@ ...@@ -200,28 +200,23 @@
const copyBtn = document.querySelector('#tokenModal .copy-btn'); const copyBtn = document.querySelector('#tokenModal .copy-btn');
const originalText = copyBtn.textContent; const originalText = copyBtn.textContent;
navigator.clipboard.writeText(tokenText.textContent).then(function() { // Use execCommand for reliable copying
copyBtn.textContent = 'Copied!'; const textArea = document.createElement('textarea');
copyBtn.style.background = '#10b981'; textArea.value = tokenText.textContent.trim();
setTimeout(function() { document.body.appendChild(textArea);
copyBtn.textContent = originalText; textArea.select();
copyBtn.style.background = ''; try {
}, 2000);
}, function(err) {
// Fallback for older browsers
const textArea = document.createElement('textarea');
textArea.value = tokenText.textContent;
document.body.appendChild(textArea);
textArea.select();
document.execCommand('copy'); document.execCommand('copy');
document.body.removeChild(textArea);
copyBtn.textContent = 'Copied!'; copyBtn.textContent = 'Copied!';
copyBtn.style.background = '#10b981'; copyBtn.style.background = '#10b981';
setTimeout(function() { setTimeout(function() {
copyBtn.textContent = originalText; copyBtn.textContent = originalText;
copyBtn.style.background = ''; copyBtn.style.background = '';
}, 2000); }, 2000);
}); } catch (err) {
alert('Failed to copy token. Please select and copy manually.');
}
document.body.removeChild(textArea);
} }
// Close modal when clicking outside // Close modal when clicking outside
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment