Skip to content

Commit 55bde59

Browse files
Update counter-block.html
1 parent 8ac5cf4 commit 55bde59

1 file changed

Lines changed: 9 additions & 25 deletions

File tree

worker/counter-block.html

Lines changed: 9 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,23 @@
11
<!--
2-
DROP-IN REPLACEMENT for the GoatCounter badge script in index.html.
2+
Counter block for index.html — every request increments. No session guard.
33
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.
186
-->
197
<script>
208
(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/';
2213
var box=document.getElementById('visits'),
2314
n=document.getElementById('vCount');
2415
if(!box||!n) return;
2516

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(); })
3419
.then(function(d){
3520
if(typeof d.count!=='number') throw new Error('bad payload');
36-
if(!counted){ try{ sessionStorage.setItem('rmm_counted','1'); }catch(e){} }
3721
n.textContent=d.count;
3822
box.classList.add('show');
3923
})

0 commit comments

Comments
 (0)