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