aboutsummaryrefslogtreecommitdiff
path: root/static/js/code-copy.ts
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/code-copy.ts')
-rw-r--r--static/js/code-copy.ts22
1 files changed, 22 insertions, 0 deletions
diff --git a/static/js/code-copy.ts b/static/js/code-copy.ts
new file mode 100644
index 0000000..8ef777b
--- /dev/null
+++ b/static/js/code-copy.ts
@@ -0,0 +1,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,
+ );
+ }
+ },
+ );
+})();