Add css/improving-poke.js

This commit is contained in:
ashley 2025-11-07 12:48:29 +01:00
parent 6ec6012b2b
commit 276d698626

36
css/improving-poke.js Normal file
View File

@ -0,0 +1,36 @@
function sendStats(videoId) {
if (!videoId) return
try {
if (localStorage.getItem("poke_stats_optout") === "1") return
} catch (e) {
return
}
let userId
try {
userId = localStorage.getItem("poke_uid")
if (!userId) {
userId = "u_" + Math.random().toString(36).slice(2) + Date.now()
localStorage.setItem("poke_uid", userId)
}
} catch (e) {
return
}
const payload = JSON.stringify({ videoId, userId })
if (navigator.sendBeacon) {
const blob = new Blob([payload], { type: "application/json" })
navigator.sendBeacon("/api/stats", blob)
} else {
fetch("/api/stats", {
method: "POST",
headers: { "Content-Type": "application/json" },
body: payload,
keepalive: true
}).catch(() => {})
}
}
sendStats(new URLSearchParams(location.search).get("v"))