diff options
author | tdro <tdro@noreply.example.com> | 2022-05-03 04:25:49 -0400 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2022-05-03 04:25:49 -0400 |
commit | e92dc018e28ba8d44f1c6cbc9fb0b779dec271e6 (patch) | |
tree | 3667043819ab91065019dfe3b4ff83ad625c2b49 /static/js/code-copy.ts | |
download | canory-e92dc018e28ba8d44f1c6cbc9fb0b779dec271e6.tar.gz canory-e92dc018e28ba8d44f1c6cbc9fb0b779dec271e6.tar.bz2 canory-e92dc018e28ba8d44f1c6cbc9fb0b779dec271e6.zip |
config.yaml: Commission
Diffstat (limited to 'static/js/code-copy.ts')
-rw-r--r-- | static/js/code-copy.ts | 22 |
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, + ); + } + }, + ); +})(); |