Skip to content

Commit 8e05b1f

Browse files
Update visit counter API to countapi clone
1 parent 55bde59 commit 8e05b1f

1 file changed

Lines changed: 9 additions & 26 deletions

File tree

index.html

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -512,39 +512,22 @@ <h2 id="mTitle">Open this page?</h2>
512512
otherwise the endpoint sends no CORS header and the badge stays hidden.
513513
========================================================================== */
514514
(function(){
515-
/* Self-hosted visit counter — Cloudflare Worker + KV. See worker/SETUP.md.
516-
REMAINING STEP: after `npx wrangler deploy`, put your real workers.dev
517-
URL in API below. Until that is done the badge falls back to the old
518-
GoatCounter total so the number keeps showing. Once API is set, the
519-
goat() fallback never runs and can be deleted. */
520-
var API='https://rmm-counter.YOUR-SUBDOMAIN.workers.dev/';
515+
/* Visit counter — countapi clone (countapi.mileshilliard.com).
516+
Every page load hits /hit and increments by 1. */
517+
var API='https://countapi.mileshilliard.com/api/v1/hit/realmathmodel_github_io_visits';
521518
var box=document.getElementById('visits'),
522519
n=document.getElementById('vCount');
523520
if(!box||!n) return;
524521

525-
function paint(v){ n.textContent=v; box.classList.add('show'); }
526-
527-
function goat(){
528-
fetch('https://realmathmodel.goatcounter.com/counter/TOTAL.json',{cache:'no-store'})
529-
.then(function(r){ if(!r.ok)throw new Error('HTTP '+r.status); return r.json(); })
530-
.then(function(d){ paint(d.count); })
531-
.catch(function(){ /* endpoint off or blocked — leave badge hidden */ });
532-
}
533-
534-
if(API.indexOf('YOUR-SUBDOMAIN')>-1){ goat(); return; }
535-
536-
/* One increment per tab session, so hash-route clicks don't inflate it. */
537-
var counted=false;
538-
try{ counted = sessionStorage.getItem('rmm_counted')==='1'; }catch(e){}
539-
540-
fetch(API,{method: counted ? 'GET' : 'POST', cache:'no-store', mode:'cors'})
522+
fetch(API,{cache:'no-store'})
541523
.then(function(r){ if(!r.ok)throw new Error('HTTP '+r.status); return r.json(); })
542524
.then(function(d){
543-
if(typeof d.count!=='number') throw new Error('bad payload');
544-
if(!counted){ try{ sessionStorage.setItem('rmm_counted','1'); }catch(e){} }
545-
paint(d.count);
525+
var v = (d && (d.value!=null ? d.value : d.count));
526+
if(v==null) throw new Error('bad payload');
527+
n.textContent=v;
528+
box.classList.add('show');
546529
})
547-
.catch(function(){ /* worker down or blocked — leave badge hidden */ });
530+
.catch(function(){ /* endpoint off or blocked — leave badge hidden */ });
548531
})();
549532
</script>
550533

0 commit comments

Comments
 (0)