diff options
| author | igorechek06 <me@igorek.dev> | 2024-08-22 01:01:32 +0900 |
|---|---|---|
| committer | igorechek06 <me@igorek.dev> | 2024-08-22 01:01:32 +0900 |
| commit | e112d9461e05f44abcde621bcbcb61fb24d06caa (patch) | |
| tree | 132261ec9988eaf49e2825d6e0a98a83fea7ec0a /script.js | |
| parent | 0d9b63c7075610af96985d3574d3dc8410b19977 (diff) | |
| download | pages-e112d9461e05f44abcde621bcbcb61fb24d06caa.tar.gz pages-e112d9461e05f44abcde621bcbcb61fb24d06caa.zip | |
Change site stylistic
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 | }; |
