|
1 | 1 | <!-- |
2 | | - DROP-IN REPLACEMENT for the GoatCounter badge script in index.html. |
| 2 | + Counter block for index.html — every request increments. No session guard. |
3 | 3 |
|
4 | | - Find this exact block (near the bottom of <body>) and replace the whole |
5 | | - IIFE with the one below. Nothing else in index.html changes: |
6 | | -
|
7 | | - (function(){ |
8 | | - var box=document.getElementById('visits'), |
9 | | - n=document.getElementById('vCount'); |
10 | | - fetch('https://realmathmodel.goatcounter.com/counter/TOTAL.json',{cache:'no-store'}) |
11 | | - .then(function(r){ if(!r.ok)throw new Error('HTTP '+r.status); return r.json(); }) |
12 | | - .then(function(d){ n.textContent=d.count; box.classList.add('show'); }) |
13 | | - .catch(function(){ }); |
14 | | - })(); |
15 | | -
|
16 | | - The .visits CSS stays as-is. The badge markup stays as-is. The GoatCounter |
17 | | - beacon <script> stays as-is. |
| 4 | + Replace the existing counter IIFE in index.html with the one below. |
| 5 | + Set API to your deployed workers.dev URL. Nothing else changes. |
18 | 6 | --> |
19 | 7 | <script> |
20 | 8 | (function(){ |
21 | | - var API='https://rmm-counter.YOUR-SUBDOMAIN.workers.dev/'; /* <-- set after deploy */ |
| 9 | + /* Self-hosted visit counter — Cloudflare Worker + KV. See worker/SETUP.md. |
| 10 | + Set API to your real workers.dev URL after `npx wrangler deploy`. |
| 11 | + Every request increments: no session guard, no dedupe. */ |
| 12 | + var API='https://rmm-counter.YOUR-SUBDOMAIN.workers.dev/'; |
22 | 13 | var box=document.getElementById('visits'), |
23 | 14 | n=document.getElementById('vCount'); |
24 | 15 | if(!box||!n) return; |
25 | 16 |
|
26 | | - /* One increment per tab session. Hash-route changes re-run nothing here, |
27 | | - but a full reload in the same tab also won't double-count within a tab |
28 | | - session; other tabs and later sessions each count once. */ |
29 | | - var counted=false; |
30 | | - try{ counted = sessionStorage.getItem('rmm_counted')==='1'; }catch(e){} |
31 | | - |
32 | | - fetch(API,{method: counted ? 'GET' : 'POST', cache:'no-store', mode:'cors'}) |
33 | | - .then(function(r){ if(!r.ok) throw new Error('HTTP '+r.status); return r.json(); }) |
| 17 | + fetch(API,{method:'POST', cache:'no-store', mode:'cors'}) |
| 18 | + .then(function(r){ if(!r.ok)throw new Error('HTTP '+r.status); return r.json(); }) |
34 | 19 | .then(function(d){ |
35 | 20 | if(typeof d.count!=='number') throw new Error('bad payload'); |
36 | | - if(!counted){ try{ sessionStorage.setItem('rmm_counted','1'); }catch(e){} } |
37 | 21 | n.textContent=d.count; |
38 | 22 | box.classList.add('show'); |
39 | 23 | }) |
|
0 commit comments