16 lines
467 B
JavaScript
16 lines
467 B
JavaScript
document.addEventListener("click", async (event) => {
|
|
const button = event.target.closest("[data-copy]");
|
|
if (!button) return;
|
|
const value = button.getAttribute("data-copy") || "";
|
|
try {
|
|
await navigator.clipboard.writeText(value);
|
|
const original = button.textContent;
|
|
button.textContent = "已复制";
|
|
setTimeout(() => {
|
|
button.textContent = original;
|
|
}, 1200);
|
|
} catch {
|
|
window.prompt("复制下面的内容", value);
|
|
}
|
|
});
|