From 81311c9a72058fedf0b9add696db170349478ebe Mon Sep 17 00:00:00 2001 From: Aki Date: Wed, 8 Jul 2020 22:41:18 +0200 Subject: Changed to short circuit non-null just in case --- track.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/track.js b/track.js index cb8ab72..9447b78 100644 --- a/track.js +++ b/track.js @@ -13,6 +13,7 @@ }, false) window.addEventListener("beforeunload", ()=>{ let xhr = new XMLHttpRequest() + startedAt = startedAt || new Date() xhr.open("POST", "https://stats.ignore.pl/entry") xhr.setRequestHeader("Content-Type", "application/json") xhr.send(JSON.stringify({ @@ -20,7 +21,7 @@ "referrer": document.referrer, "startedAt": startedAt, "timeSpent": Math.floor((new Date() - startedAt) / 1000), - "scrolledTo": scrolledTo / document.scrollingElement.scrollHeight + "scrolledTo": (scrolledTo || 0) / document.scrollingElement.scrollHeight })) }) })() -- cgit v1.1