blob: 751f2aef830d402b6e3f1873a93d828f5a54fdfb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
|
document.addEventListener("click", async (e) => {
const el = e.target.closest("[data-copy]");
if (!el) return;
try {
await navigator.clipboard.writeText(el.dataset.copy);
} catch (err) {
console.error("copy failed:", err);
return;
}
const scope = el.closest("[data-copy-scope]") ?? el;
scope.setAttribute("data-copied", "");
clearTimeout(scope._copyTimer);
scope._copyTimer = setTimeout(() => scope.removeAttribute("data-copied"), 1500);
});
|