function addCopyButtons() {
    for (const code of document.getElementsByTagName("code")) {
        if (code.parentElement.tagName !== "PRE") continue;

        const button = document.createElement("button");
        button.className = "copy-code-button";
        button.innerText = "Copy";

        button.addEventListener("click", ev => {
            navigator.clipboard.writeText(code.innerText);
        });

        code.parentElement.appendChild(button);
    }
}

document.addEventListener("DOMContentLoaded", addCopyButtons);