From 445908b34afb0ffb57a812f57fce6c042cc65bbf Mon Sep 17 00:00:00 2001 From: Nikita Karamov Date: Fri, 23 Dec 2022 03:08:22 +0100 Subject: [PATCH] Check for instance at the very beginning --- src/count.js | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) diff --git a/src/count.js b/src/count.js index a69f3d0..d1aa79a 100644 --- a/src/count.js +++ b/src/count.js @@ -32,32 +32,31 @@ // Check if the default GC URL resolves // This allows us to not track people with ad blockers -fetch("//gc.zgo.at/", { method: "HEAD" }) - .then((result) => { - if (!result.ok) { - return; - } - if ( - window.location.host !== "toot.kytta.dev" && - window.location.host !== "s2f.kytta.dev" && - window.location.host !== "share2fedi.kytta.dev" - ) { - return; - } +if ( + window.location.host === "toot.kytta.dev" || + window.location.host === "s2f.kytta.dev" || + window.location.host === "share2fedi.kytta.dev" +) { + fetch("//gc.zgo.at/", { method: "HEAD" }) + .then((result) => { + if (!result.ok) { + return; + } - const screen = encodeURIComponent( - [ - window.screen.width, - window.screen.height, - window.devicePixelRatio || 1, - ].join(",") - ); + const screen = encodeURIComponent( + [ + window.screen.width, + window.screen.height, + window.devicePixelRatio || 1, + ].join(",") + ); - const random = encodeURIComponent(Math.random().toString(36).slice(2)); + const random = encodeURIComponent(Math.random().toString(36).slice(2)); - navigator.sendBeacon( - `https://share2fedi.goatcounter.com/count?p=%2F&s=${screen}&b=0&rnd=${random}` - ); - }) - .catch((_) => {}); + navigator.sendBeacon( + `https://share2fedi.goatcounter.com/count?p=%2F&s=${screen}&b=0&rnd=${random}` + ); + }) + .catch((_) => {}); +}