forked from mirrors/hugo-theme-terminal
revamp code highlighting
This commit is contained in:
20
assets/js/copy-to-clipboard.js
Normal file
20
assets/js/copy-to-clipboard.js
Normal file
@ -0,0 +1,20 @@
|
||||
const blockcodes = document.querySelectorAll(".chroma code[data-lang]");
|
||||
|
||||
for (const bc of blockcodes) {
|
||||
const parent = bc.parentElement;
|
||||
const content = bc.innerText.split("\n").filter(Boolean).join("\n");
|
||||
const cpbutton = document.createElement("button");
|
||||
cpbutton.classList.add("copy-button");
|
||||
cpbutton.innerText = "Copy";
|
||||
|
||||
cpbutton.addEventListener("click", () => {
|
||||
cpbutton.innerText = "Copied";
|
||||
setTimeout(() => {
|
||||
cpbutton.innerText = "Copy";
|
||||
}, 1000);
|
||||
|
||||
navigator.clipboard.writeText(content);
|
||||
});
|
||||
|
||||
parent.prepend(cpbutton);
|
||||
}
|
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user