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