aboutsummaryrefslogtreecommitdiffhomepage
path: root/script.js
blob: 2f428b997efa461a4f30369691b7af9030242427 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
function copy(text, tooltip) {
  return () => {
    navigator.clipboard.writeText(text);
    tooltip.textContent = " []";
    setTimeout(() => (tooltip.textContent = " []"), 1000);
  };
}

window.onload = () => {
  document.querySelectorAll(".copy").forEach((element) => {
    const tooltip = document.createElement("span");
    tooltip.classList.add("copy-button");
    tooltip.textContent = " []";

    element.onclick = copy(element.attributes["copy-text"]?.value, tooltip);
    element.appendChild(tooltip);
  });
};