blob: 3ca7d303aae1dedc61f80ce787a4969262118d7e (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
document.querySelectorAll(".toggle-vision").forEach((button) => {
button.addEventListener("click", function () {
const codeBlock = this.closest(".code-block").querySelector(".inner");
codeBlock.classList.toggle("hidden");
this.textContent = codeBlock.classList.contains("hidden")
? "Show code"
: "Hide code";
});
});
document.querySelectorAll(".inner .cs-btn").forEach((button) => {
button.addEventListener("click", function () {
const codeElement = this.closest(".inner").querySelector("code");
const codeToCopy = codeElement.textContent;
navigator.clipboard
.writeText(codeToCopy)
.then(() => {
this.textContent = "Copied!";
setTimeout(() => {
this.textContent = "Copy";
}, 2000);
})
.catch((err) => {
console.error("Failed to copy code: ", err);
});
});
});
|