2024-11-05 11:12:42 +00:00
|
|
|
// @ts-check
|
|
|
|
|
|
|
|
const codeBlocks = document.querySelectorAll("pre");
|
|
|
|
|
|
|
|
if (codeBlocks) {
|
|
|
|
try {
|
|
|
|
codeBlocks?.forEach((codeBlock) => {
|
2024-12-05 07:03:33 +00:00
|
|
|
if (codeBlock.classList.contains("skip-js")) return;
|
2024-11-05 11:12:42 +00:00
|
|
|
codeBlock.style.position = "relative";
|
|
|
|
|
|
|
|
const copyCodeButton = document.createElement("span");
|
2024-12-05 07:03:33 +00:00
|
|
|
// copyCodeButton.style.position = "absolute";
|
|
|
|
// copyCodeButton.style.top = "10px";
|
|
|
|
// copyCodeButton.style.right = "10px";
|
2024-11-05 11:12:42 +00:00
|
|
|
copyCodeButton.style.cursor = "pointer";
|
2024-12-05 07:03:33 +00:00
|
|
|
// copyCodeButton.style.display = "none";
|
2024-11-05 11:12:42 +00:00
|
|
|
|
|
|
|
copyCodeButton.addEventListener("click", () => {
|
|
|
|
// console.log(codeBlock.innerText);
|
|
|
|
// console.log(codeBlock.textContent);
|
|
|
|
navigator.clipboard.writeText(codeBlock.innerText).then(() => {
|
|
|
|
window.alert("Code Copied!");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const copyIcon = document.createElement("img");
|
|
|
|
copyIcon.src = "/images/copy.png";
|
|
|
|
copyIcon.width = 16;
|
|
|
|
copyIcon.height = 16;
|
|
|
|
|
|
|
|
copyCodeButton.appendChild(copyIcon);
|
|
|
|
|
|
|
|
codeBlock.appendChild(copyCodeButton);
|
|
|
|
});
|
|
|
|
} catch (error) {}
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener("click", (e) => {
|
|
|
|
const cancelBlocks = document.querySelectorAll(".window-cancel");
|
|
|
|
/** @type {HTMLElement} */ // @ts-ignore
|
|
|
|
const targetEl = e.target;
|
|
|
|
cancelBlocks.forEach((el) => {
|
|
|
|
if (targetEl.closest(".window-cancel")) return;
|
|
|
|
el.classList.add("hidden");
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
const queryUrls = document.querySelectorAll("a.query-url");
|
|
|
|
queryUrls.forEach((urlEl) => {
|
|
|
|
const urlHref = urlEl.getAttribute("href");
|
|
|
|
|
|
|
|
if (!urlHref?.match(/\?/)) {
|
|
|
|
urlEl.setAttribute("href", `${urlHref}${window.location.search}`);
|
|
|
|
}
|
|
|
|
});
|