aboutsummaryrefslogtreecommitdiff
path: root/static/js/code-copy.ts
blob: 8ef777b21dadcd45364e1ff1b506a7112356f3c3 (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 :not(.ln a)")]
    .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,
          );
        }
      },
    );
})();