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