summaryrefslogtreecommitdiff
path: root/public/copy.js
diff options
context:
space:
mode:
Diffstat (limited to 'public/copy.js')
-rw-r--r--public/copy.js14
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);
+});