datatrash/static/copy.js

14 lines
477 B
JavaScript

if (navigator.clipboard) {
const buttons = document.querySelectorAll("button[data-copy], a[data-copy]");
for (const button of buttons) {
button.classList.remove("hidden");
button.onclick = () => {
const target = document.querySelector(button.getAttribute("data-copy"));
navigator.clipboard.writeText(target.textContent).then(
(_) => (button.innerText = "kopiert!"),
(_) => (button.innerText = "nicht unterstützt")
);
};
}
}