MCPcopy Create free account
hub / github.com/027xiguapi/code-box / onCopy

Function onCopy

contents/copycode.tsx:80–102  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

78 }
79
80 const onCopy = async () => {
81 try {
82 const target = anchor.element as HTMLElement
83 const preBlock = target.closest("pre")
84 const codeBlock = target.querySelector("code")
85 let textContent = ""
86
87 if (codeBlock) {
88 textContent = codeBlock.innerText
89 } else {
90 textContent = preBlock && preBlock.innerText
91 }
92
93 navigator.clipboard.writeText(textContent)
94
95 setIsCopy(true)
96 setTimeout(() => {
97 setIsCopy(false)
98 }, 1000)
99 } catch (error) {
100 console.log(error)
101 }
102 }
103
104 return (
105 <>

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected