36 lines
1.3 KiB
JavaScript
36 lines
1.3 KiB
JavaScript
// Secret toggle: `.pw` cells are masked by default. A global "Reveal" button
|
|
// (`.reveal-all`) toggles visibility. Clicking a `.pw` cell copies its value.
|
|
document.addEventListener("DOMContentLoaded", () => {
|
|
const mask = (el) => {
|
|
if (!el.dataset.real) el.dataset.real = el.textContent;
|
|
el.dataset.masked = "";
|
|
el.textContent = el.dataset.real.replace(/./g, "•");
|
|
};
|
|
|
|
document.querySelectorAll(".pw").forEach((el) => mask(el));
|
|
|
|
const revealAll = document.querySelector(".reveal-all");
|
|
if (revealAll) {
|
|
revealAll.addEventListener("click", () => {
|
|
const on = revealAll.dataset.on === "1";
|
|
document.querySelectorAll(".pw").forEach((el) => {
|
|
if (on) mask(el);
|
|
else el.textContent = el.dataset.real || el.textContent;
|
|
});
|
|
revealAll.dataset.on = on ? "" : "1";
|
|
revealAll.textContent = on ? "Reveal secrets" : "Hide secrets";
|
|
});
|
|
}
|
|
|
|
document.querySelectorAll(".pw").forEach((el) => {
|
|
el.addEventListener("click", () => {
|
|
const real = el.dataset.real || el.textContent;
|
|
navigator.clipboard?.writeText(real).then(() => {
|
|
const prev = el.textContent;
|
|
el.textContent = "copied ✓";
|
|
setTimeout(() => { el.textContent = prev; }, 700);
|
|
}).catch(() => {});
|
|
});
|
|
});
|
|
});
|