aboutsummaryrefslogtreecommitdiffhomepage
path: root/script.js
diff options
context:
space:
mode:
Diffstat (limited to 'script.js')
-rw-r--r--script.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/script.js b/script.js
new file mode 100644
index 0000000..b16142f
--- /dev/null
+++ b/script.js
@@ -0,0 +1,18 @@
1function copy(text, tooltip) {
2 return () => {
3 navigator.clipboard.writeText(text);
4 tooltip.textContent = "[copied]";
5 setTimeout(() => (tooltip.textContent = "[click to copy]"), 1000);
6 };
7}
8
9window.onload = () => {
10 document.querySelectorAll(".copy").forEach((element) => {
11 const tooltip = document.createElement("span");
12 tooltip.classList.add("copy-tooltip");
13 tooltip.textContent = "[click to copy]";
14
15 element.onclick = copy(element.attributes["copy-text"]?.value, tooltip);
16 element.appendChild(tooltip);
17 });
18};