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