Files
tsuki/assets/js/code-copy.js
T
tiennm99 6e17ee62b9 fix: address v0.1.0 audit findings and security notes
Fixes issues flagged in audit: improve footer spacing, meta tag refinement,
code-copy utility robustness, and add security notes to data schemas.
2026-05-09 09:32:17 +07:00

26 lines
722 B
JavaScript

const COPY = "Sao chép";
const COPIED = "Đã chép";
const FAILED = "Lỗi";
if (navigator.clipboard) {
for (const pre of document.querySelectorAll("pre")) {
const code = pre.querySelector("code");
if (!code) continue;
const btn = document.createElement("button");
btn.type = "button";
btn.className = "code-copy";
btn.setAttribute("aria-label", COPY);
btn.textContent = COPY;
pre.appendChild(btn);
btn.addEventListener("click", async () => {
try {
await navigator.clipboard.writeText(code.innerText);
btn.textContent = COPIED;
} catch {
btn.textContent = FAILED;
}
setTimeout(() => { btn.textContent = COPY; }, 1500);
});
}
}