`; }; const hidePopup = () => { document.querySelector(".ppf-popup").style.display = "none"; document.querySelector(".ppf-popup").innerHTML = ``; const scrollY = document.body.style.top; document.body.style.position = ''; document.body.style.top = ''; document.body.style.left = ''; document.body.style.right = ''; window.scrollTo(0, parseInt(scrollY || '0') * -1); }; const onExitIntent = (e) => { if (e.clientY <= 0) { document.removeEventListener("mouseleave", onExitIntent); updateLocalStorage(); const quizURL = "".replace("#open-quiz-", ""); displayPopup(quizURL); } }; const onScroll = () => { if (window.scrollY >= autoTriggerScrollValue) { document.removeEventListener("scroll", onScroll); updateLocalStorage(); const quizURL = "".replace("#open-quiz-", ""); displayPopup(quizURL); } }; const onTimeout = () => { updateLocalStorage(); const quizURL = "".replace("#open-quiz-", ""); displayPopup(quizURL); }; const popupFrequency = "once"; const autoTriggerOnExitIntent = false; const autoTriggerOnScroll = false; const autoTriggerScrollValue = 250; const autoTriggerAfterXSeconds = false; const autoTriggerTimeValue = 10; const popupShown = localStorage.getItem("ppf-popup-shown"); const popupShownCount = localStorage.getItem("ppf-popup-shown-count"); const popupShownTimestamp = localStorage.getItem("ppf-popup-shown-timestamp"); const popupShownDate = new Date(parseInt(popupShownTimestamp)); const shouldShowPopup = (popupFrequency === "once" && !popupShown) || (popupFrequency === "twice" && (!popupShown || popupShownCount < 2)) || (popupFrequency === "thrice" && (!popupShown || popupShownCount < 3)) || (popupFrequency === "always") || (popupFrequency === "hourly" && (!popupShown || popupShownDate.getHours() !== new Date().getHours())) || (popupFrequency === "daily" && (!popupShown || popupShownDate.getDate() !== new Date().getDate())) || (popupFrequency === "weekly" && (!popupShown || popupShownDate.getDay() !== new Date().getDay())) || (popupFrequency === "monthly" && (!popupShown || popupShownDate.getMonth() !== new Date().getMonth())) || (popupFrequency === "yearly" && (!popupShown || popupShownDate.getFullYear() !== new Date().getFullYear())); if (shouldShowPopup && autoTriggerOnExitIntent) { document.addEventListener("mouseleave", onExitIntent); } if (shouldShowPopup && autoTriggerOnScroll && autoTriggerScrollValue >= 0) { document.addEventListener("scroll", onScroll); } if (shouldShowPopup && autoTriggerAfterXSeconds && autoTriggerTimeValue >= 0) { setTimeout(onTimeout, autoTriggerTimeValue * 1000); } document.addEventListener("click", (e) => { let targetElement = e.target; while (targetElement && targetElement !== document) { if (targetElement.tagName === 'A' && targetElement.getAttribute("href")?.startsWith("#open-quiz-")) { e.preventDefault(); const quizURL = targetElement.getAttribute("href").replace("#open-quiz-", ""); displayPopup(quizURL); return; } if (targetElement.classList?.contains("ppf-popup-close")) { hidePopup(); return; } targetElement = targetElement.parentNode; } }); }