summaryrefslogtreecommitdiff
path: root/src/static/js/clipboard.js
blob: 5cbad5d1cf7a901bfc812ed115df460083b90ba8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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;
}