(()=>{ let startedAt = null let scrolledTo = null window.addEventListener("load", ()=>{ startedAt = new Date() scrolledTo = window.scrollY if (window.innerHeight > document.scrollingElement.scrollHeight) { scrolledTo = document.scrollingElement.scrollHeight } }) window.addEventListener("scroll", (event)=>{ scrolledTo = Math.max(scrolledTo, window.scrollY + window.innerHeight) }, false) window.addEventListener("beforeunload", ()=>{ let xhr = new XMLHttpRequest() xhr.open("POST", "https://stats.ignore.pl/entry") xhr.setRequestHeader("Content-Type", "application/json") xhr.send(JSON.stringify({ "location": document.location.href, "referrer": document.referrer, "startedAt": startedAt, "timeSpent": Math.floor((new Date() - startedAt) / 1000), "scrolledTo": scrolledTo / document.scrollingElement.scrollHeight })) }) })()