forked from vincentchan/mickey
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcopyCode.js
More file actions
20 lines (19 loc) · 853 Bytes
/
copyCode.js
File metadata and controls
20 lines (19 loc) · 853 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
// const codeBlocks = document.querySelectorAll(".highlight");
const codeBlocks = document.getElementsByClassName('highlight');
console.log(document.getElementsByClassName('highlight'));
console.log(codeBlocks);
// const copyCodeButtons = document.querySelectorAll('.copy-code-button');
const copyCodeButtons = document.getElementsByClassName('copy-code-button');
console.log('copyCodeButtons', copyCodeButtons);
console.log('1', codeBlocks, document.getElementsByClassName('highlight')[0] );
copyCodeButtons.forEach((copyCodeButton, index) => {
const code = codeBlocks[index].innerText;
console.log('sssss');
copyCodeButton.addEventListener('click', () => {
window.navigator.clipboard.writeText(code);
copyCodeButton.classList.add('copied');
setTimeout(() => {
copyCodeButton.classList.remove('copied');
}, 2000);
});
});