diff options
Diffstat (limited to 'src/static/js/clipboard.js')
| -rw-r--r-- | src/static/js/clipboard.js | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/src/static/js/clipboard.js b/src/static/js/clipboard.js new file mode 100644 index 0000000..5cbad5d --- /dev/null +++ b/src/static/js/clipboard.js @@ -0,0 +1,16 @@ +const copyToClipboard = (v) => { + navigator.clipboard.writeText(v) + .then(alert("text copied to clipboard!")); +} + +const clickEventHandler = (e) => { + e.preventDefault() + const raw = e.target.getAttributeNode("x-content"); + const content = atob(raw.value); + copyToClipboard(content); +} + +const copyables = document.getElementsByClassName("copyable"); +for (const c of copyables) { + c.onclick = clickEventHandler; +} |
