19 lines
501 B
JavaScript
19 lines
501 B
JavaScript
const link = document.getElementById("copy-link");
|
|
|
|
if (link && navigator.clipboard?.writeText) {
|
|
link.style.display = "";
|
|
link.hidden = false;
|
|
link.onclick = async (e) => {
|
|
e.preventDefault();
|
|
try {
|
|
await navigator.clipboard.writeText(`${location.origin}/${link.dataset.id}`);
|
|
link.textContent = "copied";
|
|
setTimeout(() => {
|
|
link.textContent = "copy link";
|
|
}, 2000);
|
|
} catch (error) {
|
|
console.error("failed to copy link:", error);
|
|
}
|
|
};
|
|
}
|