mirror of
https://github.com/EnixCoda/Gitako.git
synced 2026-03-11 08:54:44 +00:00
feat: show no more than one copy snippet button
This commit is contained in:
parent
859948c443
commit
441562a6ac
1 changed files with 7 additions and 3 deletions
|
|
@ -161,6 +161,7 @@ export function attachCopySnippet() {
|
|||
* </article>
|
||||
*/
|
||||
if (target.parentNode) {
|
||||
removeAttachedOnes() // show no more than one button
|
||||
const clippyElement = await renderReact(
|
||||
React.createElement(Clippy, { codeSnippetElement: target }),
|
||||
)
|
||||
|
|
@ -171,14 +172,17 @@ export function attachCopySnippet() {
|
|||
}
|
||||
}
|
||||
}
|
||||
readmeElement.addEventListener('mouseover', mouseOverCallback)
|
||||
return () => {
|
||||
readmeElement.removeEventListener('mouseover', mouseOverCallback)
|
||||
function removeAttachedOnes() {
|
||||
const buttons = document.querySelectorAll(`.${ClippyClassName}`)
|
||||
buttons.forEach(button => {
|
||||
button.parentElement?.removeChild(button)
|
||||
})
|
||||
}
|
||||
readmeElement.addEventListener('mouseover', mouseOverCallback)
|
||||
return () => {
|
||||
readmeElement.removeEventListener('mouseover', mouseOverCallback)
|
||||
removeAttachedOnes()
|
||||
}
|
||||
},
|
||||
() => {
|
||||
const plainReadmeSelector = '.repository-content div#readme .plain'
|
||||
|
|
|
|||
Loading…
Reference in a new issue