33b4a72f2c
Static HTML and CSS with self-hosted Geist fonts and light/dark themes, deployed by pages.yml to https://boxpositron.github.io/envsitter/ (guard page at /guard/).
28 lines
816 B
JavaScript
28 lines
816 B
JavaScript
(() => {
|
|
if (!navigator.clipboard || !window.isSecureContext) return;
|
|
|
|
const status = document.getElementById("copy-status");
|
|
const announce = (message) => {
|
|
if (status) status.textContent = message;
|
|
};
|
|
|
|
document.querySelectorAll("button[data-copy]").forEach((button) => {
|
|
let resetTimer;
|
|
button.hidden = false;
|
|
button.addEventListener("click", async () => {
|
|
try {
|
|
await navigator.clipboard.writeText(button.dataset.copy);
|
|
button.dataset.state = "copied";
|
|
announce("Copied to clipboard");
|
|
clearTimeout(resetTimer);
|
|
resetTimer = setTimeout(() => {
|
|
delete button.dataset.state;
|
|
announce("");
|
|
}, 2000);
|
|
} catch {
|
|
announce("Copy failed. Select the text and copy it manually.");
|
|
}
|
|
});
|
|
});
|
|
})();
|