feat: show no more than one copy snippet button

This commit is contained in:
EnixCoda 2020-04-16 09:52:44 +08:00
parent 859948c443
commit 441562a6ac

View file

@ -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'