mirror of
https://code.castopod.org/adaures/castopod.git
synced 2024-09-11 21:08:06 +02:00
23 lines
664 B
TypeScript
23 lines
664 B
TypeScript
const Clipboard = (): void => {
|
|
const buttons: NodeListOf<HTMLButtonElement> | null =
|
|
document.querySelectorAll("button[data-type='clipboard-copy']");
|
|
|
|
if (buttons) {
|
|
for (let i = 0; i < buttons.length; i++) {
|
|
const button: HTMLButtonElement = buttons[i];
|
|
const element: HTMLFormElement | null = document.querySelector(
|
|
`[id="${button.dataset.clipboardTarget}"]`
|
|
);
|
|
if (element) {
|
|
button.addEventListener("click", () => {
|
|
element.select();
|
|
element.setSelectionRange(0, element.value.length);
|
|
document.execCommand("copy");
|
|
});
|
|
}
|
|
}
|
|
}
|
|
};
|
|
|
|
export default Clipboard;
|