forked from mirrors/hugo-theme-terminal
21 lines
571 B
JavaScript
21 lines
571 B
JavaScript
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);
|
|
}
|