Skip to content

Commit bd62f13

Browse files
authored
Merge pull request #920 from pre-commit/fix-copyable
fix copy script
2 parents 53baede + 525ca99 commit bd62f13

File tree

1 file changed

+2
-4
lines changed

1 file changed

+2
-4
lines changed

assets/copyable.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,13 @@
1313
document.execCommand('copy');
1414
document.body.removeChild(textArea);
1515
}
16-
const codeBlockElements = document.getElementsByClassName('copyable');
17-
for (let i = 0; i < codeBlockElements.length; i++) {
18-
const block = codeBlockElements[i];
16+
for (const block of document.getElementsByClassName('copyable')) {
1917
const copyIcon = new Image(16, 16);
2018
copyIcon.setAttribute('src', './assets/copy-icon.svg');
2119
copyIcon.setAttribute('alt', 'copy');
2220
copyIcon.setAttribute('title', 'copy to clipboard');
2321
block.insertBefore(copyIcon, block.children[0]);
24-
copyIcon.addEventListener('click', (block) => {
22+
copyIcon.addEventListener('click', () => {
2523
const text = block.getElementsByTagName('pre')[0].innerText;
2624
copyTextToClipboard(text);
2725
});

0 commit comments

Comments
 (0)