diff options
author | tdro <tdro@noreply.example.com> | 2022-08-02 21:47:53 -0400 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2022-08-02 21:47:53 -0400 |
commit | 93ff2963616968f377d63f02bb0fa206144da7ae (patch) | |
tree | c6f6be30e625708bea33bba5f4bb763f763b6d65 /static/js/codecopy.ts | |
parent | c9bbcb3bda9666eb02dd6ed2f12308de4394d60a (diff) | |
download | canory-93ff2963616968f377d63f02bb0fa206144da7ae.tar.gz canory-93ff2963616968f377d63f02bb0fa206144da7ae.tar.bz2 canory-93ff2963616968f377d63f02bb0fa206144da7ae.zip |
static/js/code-copy.ts -> codecopy.ts
Diffstat (limited to 'static/js/codecopy.ts')
-rw-r--r-- | static/js/codecopy.ts | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/static/js/codecopy.ts b/static/js/codecopy.ts new file mode 100644 index 0000000..4c22d07 --- /dev/null +++ b/static/js/codecopy.ts @@ -0,0 +1,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, + ); + } + }, + ); +})(); |