Skip to content

Commit f13d251

Browse files
committed
feat(pastes): copy button
1 parent c28b9f9 commit f13d251

File tree

1 file changed

+17
-7
lines changed

1 file changed

+17
-7
lines changed

pkg/apps/pastes/html/post.page.tmpl

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -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>

0 commit comments

Comments
 (0)