mirror of
https://github.com/tiennm99/tsuki.git
synced 2026-05-28 10:24:22 +00:00
6e17ee62b9
Fixes issues flagged in audit: improve footer spacing, meta tag refinement, code-copy utility robustness, and add security notes to data schemas.
26 lines
722 B
JavaScript
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);
|
|
});
|
|
}
|
|
}
|