Commit f13d251

Eric Bower  ·  2025-08-02 13:40:35 -0400 EDT
parent c28b9f9
feat(pastes): copy button
1 files changed,  +17, -7
+17, -7
......@@ -35,15 +35,25 @@
3535 <a href="{{.RawURL}}">raw</a>
3636 </p>
3737 <p class="font-bold m-0">expires: {{.ExpiresAt}}</p>
38+ <script>
39+ function init() {
40+ const btn = document.querySelector("#copy-btn");
41+ const res = document.querySelector("#copy-result");
42+ const text = "{{.Text}}";
43+ btn.addEventListener("click", () => {
44+ res.innerHtml = "";
45+ navigator.clipboard.writeText(text)
46+ .then(() => res.innerHTML = "success!");
47+ })
48+ }
49+ document.addEventListener("DOMContentLoaded", init);
50+ </script>
3851 </header>
3952 <main>
40-<script>
41-function copyText() {
42- const text = `{{.Text}}`
43- navigator.clipboard.writeText(text)
44-}
45-</script>
46- <button onclick="copyText()" class="btn mt inline-block">Copy Paste</button>
53+ <div class="flex gap items-center">
54+ <button id="copy-btn" class="btn" style="background-color: transparent;">copy</button>
55+ <div id="copy-result" class=""></div>
56+ </div>
4757 <article>
4858 {{.Contents}}
4959 </article>