diff --git a/html/watch.ejs b/html/watch.ejs index 009ffa65..f21a8107 100644 --- a/html/watch.ejs +++ b/html/watch.ejs @@ -2431,10 +2431,25 @@ if (/[?&]autoplay=/.test(location.search)) { function sendStats(videoId) { if (!videoId) return - let userId = localStorage.getItem("poke_uid") - if (!userId) { - userId = "u_" + Math.random().toString(36).slice(2) + Date.now() - localStorage.setItem("poke_uid", userId) + // respect per-browser opt-out + try { + if (localStorage.getItem("poke_stats_optout") === "1") return + } catch (e) { + // if localStorage is blocked, just don't send anything + 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) { + // if we can't read/write localStorage, don't send stats + return } const payload = { videoId, userId } @@ -2447,7 +2462,6 @@ function sendStats(videoId) { }).catch(() => {}) } - sendStats(new URLSearchParams(location.search).get("v")) function toggleTheaterMode() {