mirror of
https://github.com/fruworg/themu.git
synced 2024-11-16 07:07:16 +03:00
copy
This commit is contained in:
parent
c436d2225a
commit
96356946d0
@ -0,0 +1,22 @@
|
|||||||
|
document.addEventListener('DOMContentLoaded', function() {
|
||||||
|
const codeBlocks = document.querySelectorAll('.highlight pre code[class*="language-"]::before');
|
||||||
|
|
||||||
|
codeBlocks.forEach(codeBlock => {
|
||||||
|
codeBlock.addEventListener('click', function() {
|
||||||
|
const textToCopy = this.nextElementSibling.innerText;
|
||||||
|
copyTextToClipboard(textToCopy);
|
||||||
|
alert('Текст скопирован в буфер обмена: ' + textToCopy);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function copyTextToClipboard(text) {
|
||||||
|
const tempInput = document.createElement('textarea');
|
||||||
|
tempInput.style.position = 'absolute';
|
||||||
|
tempInput.style.left = '-9999px';
|
||||||
|
tempInput.value = text;
|
||||||
|
document.body.appendChild(tempInput);
|
||||||
|
tempInput.select();
|
||||||
|
document.execCommand('copy');
|
||||||
|
document.body.removeChild(tempInput);
|
||||||
|
}
|
||||||
|
});
|
Loading…
Reference in New Issue
Block a user