mirror of
https://github.com/tstack/lnav
synced 2024-11-09 19:10:52 +00:00
24 lines
714 B
JavaScript
24 lines
714 B
JavaScript
var codeBlocks = document.querySelectorAll('pre.highlight');
|
|
|
|
codeBlocks.forEach(function (codeBlock) {
|
|
var copyButton = document.createElement('button');
|
|
copyButton.className = 'copy';
|
|
copyButton.type = 'button';
|
|
copyButton.ariaLabel = 'Copy code to clipboard';
|
|
copyButton.innerText = 'Copy';
|
|
|
|
codeBlock.append(copyButton);
|
|
|
|
copyButton.addEventListener('click', function () {
|
|
var code = codeBlock.querySelector('code').innerText.trim();
|
|
window.navigator.clipboard.writeText(code);
|
|
|
|
copyButton.innerText = 'Copied';
|
|
var fourSeconds = 4000;
|
|
|
|
setTimeout(function () {
|
|
copyButton.innerText = 'Copy';
|
|
}, fourSeconds);
|
|
});
|
|
});
|