Update css/stats.js
This commit is contained in:
parent
87b75d1c0e
commit
00e9c0fe4f
65
css/stats.js
65
css/stats.js
@ -1,16 +1,59 @@
|
|||||||
(function addStats() {
|
(function addStats() {
|
||||||
const url = "/static/improving-poke.js"
|
const KEY = "poke_stats_script_status";
|
||||||
|
|
||||||
if (document.querySelector(`script[src="${url}"]`)) return
|
try {
|
||||||
|
const status = localStorage.getItem(KEY);
|
||||||
|
if (status === "blocked") {
|
||||||
|
console.log("[Poke] Stats script permanently disabled (network blocked)");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (status === "ok") {
|
||||||
|
return loadScript();
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
console.warn("[Poke] localStorage blocked, disabling improving-poke.js");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const s = document.createElement("script")
|
const testPayload = JSON.stringify({ test: true });
|
||||||
s.src = url
|
|
||||||
s.type = "text/javascript"
|
|
||||||
s.async = true
|
|
||||||
s.defer = true
|
|
||||||
|
|
||||||
s.onload = () => console.log("[Poke] improving-poke.js loaded successfully")
|
const test = fetch("/api/stats", {
|
||||||
s.onerror = () => console.warn("[Poke] failed to load improving-poke.js")
|
method: "POST",
|
||||||
|
headers: { "Content-Type": "application/json" },
|
||||||
|
body: testPayload,
|
||||||
|
keepalive: true,
|
||||||
|
})
|
||||||
|
.then(() => {
|
||||||
|
try {
|
||||||
|
localStorage.setItem(KEY, "ok");
|
||||||
|
} catch {}
|
||||||
|
loadScript();
|
||||||
|
})
|
||||||
|
.catch(() => {
|
||||||
|
console.warn("[Poke] Stats endpoint blocked — never loading improving script again");
|
||||||
|
try {
|
||||||
|
localStorage.setItem(KEY, "blocked");
|
||||||
|
} catch {}
|
||||||
|
});
|
||||||
|
|
||||||
document.head.appendChild(s)
|
function loadScript() {
|
||||||
})()
|
const url = "/static/improving-poke.js";
|
||||||
|
if (document.querySelector(`script[src="${url}"]`)) return;
|
||||||
|
|
||||||
|
const s = document.createElement("script");
|
||||||
|
s.src = url;
|
||||||
|
s.type = "text/javascript";
|
||||||
|
s.async = true;
|
||||||
|
s.defer = true;
|
||||||
|
|
||||||
|
s.onload = () => console.log("[Poke] improving-poke.js loaded");
|
||||||
|
s.onerror = () => {
|
||||||
|
console.warn("[Poke] script failed — marking as blocked");
|
||||||
|
try {
|
||||||
|
localStorage.setItem(KEY, "blocked");
|
||||||
|
} catch {}
|
||||||
|
};
|
||||||
|
|
||||||
|
document.head.appendChild(s);
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user