MCPcopy Create free account
hub / github.com/github/docs / copyCode

Function copyCode

components/lib/copy-code.ts:1–20  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

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

Callers 1

initiateArticleScriptsFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected