jQuery(document).ready(($) => { hidePopup() fetchPopupDelay().then((res) => { const delay = res.success ? res.data : null shouldShowPopup(delay) }) $("body").on("click", "#cancel-mobile-popup", (e) => { e.preventDefault() $(".sns-mobile-popup-container").hide(400) window.localStorage.setItem("popupLastShown", (Date.now() / 1000).toString()) }) $("body").on("click", "#open-in-app", (e) => { e.preventDefault() hidePopup() const dataLink = $("#open-in-app").data("link") if (dataLink) { window.location = dataLink } }) function hidePopup() { $(".sns-mobile-popup-container").hide(400) } /** * Show the popup if never cancelled or the number of days since last cancelled has exceeded the threshold. * @param {int|null} popupDelay The number of days to wait before showing the popup again. */ function shouldShowPopup(popupDelay) { if (!popupDelay) { hidePopup() return } const lastShown = parseFloat(window.localStorage.getItem("popupLastShown")) const now = Date.now() / 1000 if (!lastShown || lastShown + popupDelay * 86400 < now) { $(".sns-mobile-popup-container").show(400) } } }) const fetchPopupDelay = () => { return jQuery.get( "/wp-admin/admin-ajax.php", { action: "sns_fetch_popup_delay", }, "json", ) }