Fix: extract goatcounter to update hash

This commit is contained in:
Pieter Vander Vennet 2025-06-04 21:15:53 +02:00
parent 74e15527ef
commit a22946e34a
10 changed files with 24 additions and 25 deletions

View file

@ -41,9 +41,7 @@
<body>
<div id="maindiv" class="h-screen"></div>
<script type="module" src="./src/notfound.ts"></script>
<script async data-goatcounter="https://pietervdvn.goatcounter.com/count" src="//gc.zgo.at/count.js"
crossorigin="anonymous"
integrity="sha384-CpAs0JV3n+/AHsDCOxNKSnFtYyKUX6mj7BrGrvXvUvW2A/a3B31dMZD+wfNzTAJT"></script>
<script src="./src/loadGoatcounter.js"></script>
</body>
</html>

View file

@ -42,9 +42,7 @@
<div id="main"></div>
<script src="./src/Logic/Web/AndroidPolyfill.ts" type="module"></script>
<script type="module" src="./src/all_themes_index.ts"></script>
<script async data-goatcounter="https://pietervdvn.goatcounter.com/count" src="https://gc.zgo.at/count.js"
crossorigin="anonymous"
integrity="sha384-CpAs0JV3n+/AHsDCOxNKSnFtYyKUX6mj7BrGrvXvUvW2A/a3B31dMZD+wfNzTAJT"></script>
<script src="./src/loadGoatcounter.js"></script>
<script async src="./src/InstallServiceWorker.ts" type="module"></script>

View file

@ -12,9 +12,7 @@
<body>
<div id="main">Loading inspector...</div>
<script src="./src/UI/InspectorGUI.ts" type="module"></script>
<script async data-goatcounter="https://pietervdvn.goatcounter.com/count" src="//gc.zgo.at/count.js"
crossorigin="anonymous"
integrity="sha384-CpAs0JV3n+/AHsDCOxNKSnFtYyKUX6mj7BrGrvXvUvW2A/a3B31dMZD+wfNzTAJT"></script>
<script src="./src/loadGoatcounter.js"></script>
</body>
</html>

View file

@ -38,9 +38,7 @@
<div id="main"></div>
<script type="module" src="./src/privacy_index.ts"></script>
<script async data-goatcounter="https://pietervdvn.goatcounter.com/count" src="//gc.zgo.at/count.js"
crossorigin="anonymous"
integrity="sha384-CpAs0JV3n+/AHsDCOxNKSnFtYyKUX6mj7BrGrvXvUvW2A/a3B31dMZD+wfNzTAJT"></script>
<script src="./src/loadGoatcounter.js"></script>
</body>
</html>

7
src/loadGoatcounter.js Normal file
View file

@ -0,0 +1,7 @@
const script = document.createElement("script")
script.async = true
script.dataset.goatcounter = "https://pietervdvn.goatcounter.com/count"
script.src = "https://gc.zgo.at/count.js"
script.crossOrigin = "anonymous"
script.integrity = "sha384-atnOLvQb9t+jTSipvd75X2yginT4PjVbqDdlJAmxMm+wYElFmeR6EmLP5bYeoRVQ"
document.head.appendChild(script)

View file

@ -12,9 +12,7 @@
<body>
<div id="main">Loading statistics...</div>
<script src="./src/UI/StatisticsGUI.ts" type="module"></script>
<script async data-goatcounter="https://pietervdvn.goatcounter.com/count" src="//gc.zgo.at/count.js"
crossorigin="anonymous"
integrity="sha384-CpAs0JV3n+/AHsDCOxNKSnFtYyKUX6mj7BrGrvXvUvW2A/a3B31dMZD+wfNzTAJT"></script>
<script src="./src/loadGoatcounter.js"></script>
</body>
</html>

View file

@ -13,9 +13,7 @@
<body>
<div id="main"></div>
<script src="./src/UI/StatusGui.ts" type="module"></script>
<script async data-goatcounter="https://pietervdvn.goatcounter.com/count" src="//gc.zgo.at/count.js"
crossorigin="anonymous"
integrity="sha384-CpAs0JV3n+/AHsDCOxNKSnFtYyKUX6mj7BrGrvXvUvW2A/a3B31dMZD+wfNzTAJT"></script>
<script src="./src/loadGoatcounter.js"></script>
</body>
</html>

View file

@ -19,9 +19,7 @@
<body>
<div id="main" class="h-full"></div>
<script src="./src/UI/StudioGui.ts" type="module"></script>
<script async data-goatcounter="https://pietervdvn.goatcounter.com/count" src="//gc.zgo.at/count.js"
crossorigin="anonymous"
integrity="sha384-CpAs0JV3n+/AHsDCOxNKSnFtYyKUX6mj7BrGrvXvUvW2A/a3B31dMZD+wfNzTAJT"></script>
<script src="./src/loadGoatcounter.js"></script>
</body>
</html>

View file

@ -158,6 +158,14 @@ describe("Code quality", () => {
for (const htmlFile of htmlFiles) {
await validateScriptIntegrityOf(htmlFile)
}
const goatCounter = "https://gc.zgo.at/count.js"
const data: string = (await ScriptUtils.Download(goatCounter))["content"]
const hashed = await webcrypto.subtle.digest("SHA-384", new TextEncoder().encode(data))
const hashedB64 = _arrayBufferToBase64(hashed)
const goatCounterScript = readFileSync("./src/loadGoatcounter.js", "utf-8")
if (goatCounterScript.indexOf(hashedB64) < 0) {
throw "Hash sha-384" + hashedB64 + " not found in 'loadGoatcounter.js'"
}
})
/*
itAsync(
@ -168,7 +176,7 @@ describe("Code quality", () => {
)
)
/*
itAsync(
itAsync(int
"should not contain '[\"default\"]'",
detectInCode('\\[\\"default\\"\\]', "Possible leftover of faulty default import")
)*/

View file

@ -92,9 +92,7 @@
<script src="./src/Logic/Web/AndroidPolyfill.ts" type="module"></script>
<script async src="./src/InstallServiceWorker.ts" type="module"></script>
<script defer src="./src/index.ts" type="module"></script>
<script async data-goatcounter="https://pietervdvn.goatcounter.com/count" src="//gc.zgo.at/count.js"
crossorigin="anonymous"
integrity="sha384-CpAs0JV3n+/AHsDCOxNKSnFtYyKUX6mj7BrGrvXvUvW2A/a3B31dMZD+wfNzTAJT"></script>
<script src="./src/loadGoatcounter.js"></script>