if(!localStorage.getItem("popups.ts")) { localStorage.setItem("popups.ts", new Date().getTime()); } window.__popups = { ts: localStorage.getItem("popups.ts") ? Number(localStorage.getItem("popups.ts")) : new Date().getTime(), actionts: new Date().getTime(), session: loadPopupStates() } function getSecondsSinceFirstVisit() { // Ensure the __popups object and actionts are defined if (window.__popups && window.__popups.ts) { // Current timestamp const now = new Date().getTime(); // Last interaction timestamp const lastInteraction = window.__popups.ts; // Calculate the difference in milliseconds and convert to seconds const secondsSinceLastInteraction = parseInt((now - lastInteraction) / 1000); return secondsSinceLastInteraction; } else { // Return null or appropriate response if no interaction data is available return null; } } function savePopupStates() { setTimeout(function() { sessionStorage.setItem("popups", JSON.stringify(window.__popups.session)); }, 0); } function loadPopupStates() { const popupStates = sessionStorage.getItem("popups"); if(popupStates) { try { return JSON.parse(popupStates); } catch (e) {} } return { "ts": new Date().getTime() }; // fallback } // Function to update the action timestamp function updateActionTimestamp() { window.__popups.actionts = new Date().getTime(); window.__popups.session.Interactions = (window.__popups.session.Interactions ? window.__popups.session.Interactions : 0) + 1; } // Function to get seconds since the last interaction function getSecondsSinceLastInteraction() { // Ensure the __popups object and actionts are defined if (window.__popups && window.__popups.actionts) { // Current timestamp const now = new Date().getTime(); // Last interaction timestamp const lastInteraction = window.__popups.actionts; // Calculate the difference in milliseconds and convert to seconds const secondsSinceLastInteraction = parseInt((now - lastInteraction) / 1000); return secondsSinceLastInteraction; } else { // Return null or appropriate response if no interaction data is available return null; } } // List of events to listen for, representing user interaction const events = ['click', 'keydown', 'touchstart', 'mousemove']; // Add event listeners for each event in the list events.forEach(event => { document.addEventListener(event, updateActionTimestamp, { passive: true }); }); // document.addEventListener('click', function() { // loadPopup(`/popups/pricematch-popup`); // }) const subscribeUrl = "/popups/sender-net?fid=3cc33ca74863e46bilI"; const currentUrl = window.location.href; const links = document.querySelectorAll('a'); if (currentUrl.includes("/checkout-basket?promosuccess=")) { sessionStorage.setItem("popups." + subscribeUrl, true); } else { if(window.location.pathname.indexOf("/newsletter-") == 0 || window.location.pathname.indexOf("/empress-menu") == 0) { } else { // links.forEach(link => { // link.addEventListener('click', function(event) { // const hadPopup = sessionStorage.getItem("popups." + subscribeUrl); // if(!hadPopup) { // loadPopup(subscribeUrl); // return event.preventDefault(); // } // }); // }); } } const loadPopup = (url)=> { const hadPopup = sessionStorage.getItem("popups." + url); if(hadPopup) { return; } sessionStorage.setItem("popups." + url, true); return showOverlay({URL: url, W: 360, H: 1080}); }