diff options
Diffstat (limited to 'script.js')
| -rw-r--r-- | script.js | 23 |
1 files changed, 11 insertions, 12 deletions
| @@ -1,18 +1,17 @@ | |||
| 1 | function copy(text, tooltip) { | ||
| 2 | return () => { | ||
| 3 | navigator.clipboard.writeText(text); | ||
| 4 | tooltip.textContent = " []"; | ||
| 5 | setTimeout(() => (tooltip.textContent = " []"), 1000); | ||
| 6 | }; | ||
| 7 | } | ||
| 8 | |||
| 9 | window.onload = () => { | 1 | window.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 | }; |
