// async function action(action, args = {}, debug = false) { // return await $.post(`main/action.php`, {action, args}); // } var event_id = JSON.parse(`"3167"`); var status = JSON.parse(`"recorded"`); var visitor = null; var visitInterval = null; var isPageVisible = true; // Track page visibility to pause polling when tab is hidden document.addEventListener('visibilitychange', function() { isPageVisible = !document.hidden; }); action("visit", { page: window.location.href, visitor, event_id, status, }).then((res) => (visitor = res)); // Reduced polling interval from 5s to 30s, only when page is visible visitInterval = setInterval(() => { if (isPageVisible && visitor) { action("visit", { page: window.location.href, visitor }); } }, 30000);