2 Commits

Author SHA1 Message Date
bf87dc345f release: v1.2.1
All checks were successful
Node.js CI / Lint and Test (push) Successful in 46s
2025-02-16 23:17:35 -08:00
017261c80b feat: only show cta once per week
Some checks failed
Node.js CI / Lint and Test (push) Has been cancelled
2025-02-16 23:17:18 -08:00
2 changed files with 13 additions and 1 deletions

View File

@ -1,6 +1,6 @@
{
"name": "website-headers",
"version": "1.2.0",
"version": "1.2.1",
"description": "",
"main": "index.js",
"type": "module",

View File

@ -360,12 +360,24 @@ const handleModalClick = (event: MouseEvent): void => {
}
};
const showModal = (): void => {
const lastShown = Number.parseInt(
localStorage.getItem("naomi-community-cta") ?? "0",
10,
);
const lastShownDate = new Date(lastShown);
const diff = Date.now() - lastShownDate.getTime();
console.table({ diff, lastShown, lastShownDate });
// We only want to show this once a week.
if (diff < 1000 * 60 * 60 * 24 * 7) {
return;
}
cta.showModal();
modalBg.style.display = "block";
modalBg.addEventListener("click", closeModal);
const closeButton = cta.querySelector("button");
closeButton?.addEventListener("click", closeModal);
cta.addEventListener("click", handleModalClick);
localStorage.setItem("naomi-community-cta", Date.now().toString());
};
body?.appendChild(cta);