feat: add copyable links for sharing

This commit is contained in:
insects 2025-03-11 02:09:06 +01:00
parent 62a329aebd
commit 19319b8479
3 changed files with 56 additions and 12 deletions

View file

@ -22,6 +22,25 @@ function checkPwd() {
const pwd_el = document.getElementById("password");
pwd_el.innerHTML = pwd;
}
const copy_els = document.querySelectorAll(".copyable");
const cb = window.navigator.clipboard;
copy_els.forEach(el => {
el.addEventListener("click", evt => {
evt.preventDefault();
let content = el.dataset.copyContent;
if (content.includes("???")) {
content = content.replace("???", pwd);
}
cb.writeText(content).then(() => {
const curText = el.innerHTML;
el.innerHTML = "copied!";
setTimeout(() => {
el.innerHTML = curText;
}, 2000);
});
});
});
}
checkPwd();