diff options
| author | Kyren223 <contact@kyren.codes> | 2026-10-08 19:44:46 +0300 |
|---|---|---|
| committer | Kyren223 <contact@kyren.codes> | 2026-10-08 19:44:46 +0300 |
| commit | 9b03d2790b8b8db1b5a6755b6130f37e5f7f2455 (patch) | |
| tree | a84f6e9cfe2b8aaf087d55830c938443f6be683e /public/copy.js | |
| parent | 6e70fe447ec9504757fbdc152b5b3697c9af8def (diff) | |
WIP
Diffstat (limited to 'public/copy.js')
| -rw-r--r-- | public/copy.js | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/public/copy.js b/public/copy.js new file mode 100644 index 0000000..751f2ae --- /dev/null +++ b/public/copy.js @@ -0,0 +1,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); +}); |
