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,9 +197,11 @@ 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) {
btn._bound = true
btn.addEventListener("click", function () {
navigator.clipboard.writeText("curl -fsSL https://feynman.is/install | bash").then(function () { navigator.clipboard.writeText("curl -fsSL https://feynman.is/install | bash").then(function () {
var copyIcon = document.getElementById("copy-icon") var copyIcon = document.getElementById("copy-icon")
var checkIcon = document.getElementById("check-icon") var checkIcon = document.getElementById("check-icon")
@@ -211,7 +213,10 @@ const terminalCommands = [
}, 2000) }, 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() })