frontend/src/clipboard.ts
raw| 1 | import { log_error } from "./log"; |
| 2 | |
| 3 | export class CopyableText extends HTMLElement { |
| 4 | constructor() { |
| 5 | super(); |
| 6 | |
| 7 | this.addEventListener("click", (event) => { |
| 8 | const text = this.getAttribute("data-clipboard-text"); |
| 9 | if (text != null) { |
| 10 | navigator.clipboard.writeText(text).catch(log_error); |
| 11 | } |
| 12 | event.stopPropagation(); |
| 13 | }); |
| 14 | } |
| 15 | } |