24 lines
841 B
JavaScript
24 lines
841 B
JavaScript
document.querySelectorAll('[data-clipboard-text]').forEach(function(btn) {
|
|
btn.addEventListener('click', function() {
|
|
var text = btn.dataset.clipboardText;
|
|
if (navigator.clipboard) {
|
|
navigator.clipboard.writeText(text);
|
|
} else {
|
|
var ta = document.createElement('textarea');
|
|
ta.value = text;
|
|
ta.style.position = 'fixed';
|
|
ta.style.opacity = '0';
|
|
document.body.appendChild(ta);
|
|
ta.select();
|
|
document.execCommand('copy');
|
|
document.body.removeChild(ta);
|
|
}
|
|
var original = btn.textContent;
|
|
btn.textContent = '✓ Copied!';
|
|
btn.disabled = true;
|
|
setTimeout(function() {
|
|
btn.textContent = original;
|
|
btn.disabled = false;
|
|
}, 2000);
|
|
});
|
|
});
|