-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdonate.js
More file actions
35 lines (32 loc) · 1.07 KB
/
Copy pathdonate.js
File metadata and controls
35 lines (32 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Donate page — copy-to-clipboard for the wallet address (no tracking/network).
document.addEventListener("DOMContentLoaded", () => {
const btn = document.getElementById("copyBtn");
const label = document.getElementById("copyLabel");
const addr = document.getElementById("addr");
if (!btn || !addr) return;
let resetTimer = null;
btn.addEventListener("click", async () => {
const text = addr.textContent.trim();
try {
await navigator.clipboard.writeText(text);
} catch (_) {
// Fallback for older browsers / non-secure contexts.
const r = document.createRange();
r.selectNodeContents(addr);
const sel = window.getSelection();
sel.removeAllRanges();
sel.addRange(r);
try {
document.execCommand("copy");
} catch (_) {}
sel.removeAllRanges();
}
btn.classList.add("copied");
if (label) label.textContent = "Copied!";
clearTimeout(resetTimer);
resetTimer = setTimeout(() => {
btn.classList.remove("copied");
if (label) label.textContent = "Copy";
}, 1800);
});
});