aboutsummaryrefslogtreecommitdiff
path: root/static/js/codecopy.ts
blob: 9885ad8da6159936e4f35803d014a208e7a97b8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
(function () {
  [...document.querySelectorAll("pre.chroma code")]
    .forEach(
      (element) => {
        try {
          const text = element.textContent || "";
          setTimeout(
            async () => {
              await navigator.clipboard.writeText(text);
              console.log("INFO: Code text copied successfully");
            },
            3000,
          );
        } catch (error) {
          console.error("ERROR: Code text copy failed", error);
        }
      },
    );
})();