Fix copy button surviving ViewTransitions with astro:after-swap rebind

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Advait Paliwal
2026-03-24 16:20:41 -07:00
parent 4c0a417232
commit 6445c20e02

View File

@@ -197,21 +197,26 @@ const terminalCommands = [
</Layout>
<script is:inline>
;(function () {
function initCopyBtn() {
var btn = document.getElementById("install-cmd")
if (btn) btn.addEventListener("click", function () {
navigator.clipboard.writeText("curl -fsSL https://feynman.is/install | bash").then(function () {
var copyIcon = document.getElementById("copy-icon")
var checkIcon = document.getElementById("check-icon")
copyIcon.classList.add("hidden")
checkIcon.classList.remove("hidden")
setTimeout(function () {
copyIcon.classList.remove("hidden")
checkIcon.classList.add("hidden")
}, 2000)
if (btn && !btn._bound) {
btn._bound = true
btn.addEventListener("click", function () {
navigator.clipboard.writeText("curl -fsSL https://feynman.is/install | bash").then(function () {
var copyIcon = document.getElementById("copy-icon")
var checkIcon = document.getElementById("check-icon")
copyIcon.classList.add("hidden")
checkIcon.classList.remove("hidden")
setTimeout(function () {
copyIcon.classList.remove("hidden")
checkIcon.classList.add("hidden")
}, 2000)
})
})
})
})()
}
}
initCopyBtn()
document.addEventListener("astro:after-swap", initCopyBtn)
fetch("https://api.github.com/repos/getcompanion-ai/feynman")
.then(function(r) { return r.json() })