2023-01-20 17:14:18 -06:00
|
|
|
// back to top
|
|
|
|
const backToTop = document.getElementById("back-to-top");
|
|
|
|
window.onscroll = function() {
|
|
|
|
if (document.body.scrollTop > 100 || document.documentElement.scrollTop > 100) {
|
|
|
|
backToTop.style.display = "block";
|
|
|
|
} else {
|
|
|
|
backToTop.style.display = "none";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// code block copy to clipboard
|
|
|
|
window.onload = () => {
|
|
|
|
document.querySelectorAll(".code-block").forEach(codeBlock => {
|
|
|
|
const button = codeBlock.querySelector(".code-header > .code-copy-button");
|
2023-01-22 00:09:34 -06:00
|
|
|
|
|
|
|
// lang will not be unset because we default it to text
|
|
|
|
// clone it so it doesn't change the actual DOM element
|
|
|
|
const codeElem = codeBlock.querySelector("code[data-lang]").cloneNode(true);
|
|
|
|
// bashsession: remove command output lines
|
|
|
|
codeElem.querySelectorAll(".go").forEach(e => e.parentNode.removeChild(e));
|
|
|
|
// bashsession: remove prompt symbol
|
|
|
|
codeElem.querySelectorAll(".gp").forEach(e => e.parentNode.removeChild(e));
|
|
|
|
const rawCode = codeElem.innerText;
|
2023-01-20 17:14:18 -06:00
|
|
|
|
|
|
|
const originalCopyText = button.innerHTML;
|
|
|
|
button.onclick = event => {
|
|
|
|
navigator.clipboard.writeText(rawCode);
|
|
|
|
// TODO: maybe we could add a fancier indicator, like a flash or something
|
|
|
|
event.target.innerHTML = "Copied!";
|
|
|
|
setTimeout(() => {
|
|
|
|
event.target.innerHTML = originalCopyText;
|
|
|
|
}, 3000);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|