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