Register
Login
Resources
Docs Blog Datasets Glossary Case Studies Tutorials & Webinars
Product
Data Engine LLMs Platform Enterprise
Pricing Explore
Connect to our Discord channel

copy-code.ts 589 B

You have to be logged in to leave a comment. Sign In
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
  1. export default function copyCode() {
  2. const buttons = Array.from(document.querySelectorAll('button.js-btn-copy'))
  3. if (!buttons) return
  4. buttons.forEach((button) =>
  5. button.addEventListener('click', async () => {
  6. const text = (button as HTMLElement).dataset.clipboardText
  7. if (!text) return
  8. await navigator.clipboard.writeText(text)
  9. const beforeTooltip = button.getAttribute('aria-label') || ''
  10. button.setAttribute('aria-label', 'Copied!')
  11. setTimeout(() => {
  12. button.setAttribute('aria-label', beforeTooltip)
  13. }, 2000)
  14. })
  15. )
  16. }
Tip!

Press p or to see the previous file or, n or to see the next file

Comments

Loading...