From 017261c80b6d4698404e40d18151440c78dffe4b Mon Sep 17 00:00:00 2001 From: Naomi Carrigan Date: Sun, 16 Feb 2025 23:17:18 -0800 Subject: [PATCH] feat: only show cta once per week --- src/index.ts | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/index.ts b/src/index.ts index 2ec3448..ac216e0 100644 --- a/src/index.ts +++ b/src/index.ts @@ -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);