File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ < div id ="geocities-counter " class ="odometer "> 000000</ div >
2+
3+ < script >
4+ const ENDPOINT = "https://soft-starlight-cc6f91.netlify.app/api/counter" ;
5+ const SESSION_KEY = "visited-homepage" ;
6+
7+ function render ( n ) {
8+ document . getElementById ( "geocities-counter" )
9+ . textContent = String ( n ) . padStart ( 6 , "0" ) ;
10+ }
11+
12+ const firstVisit = ! sessionStorage . getItem ( SESSION_KEY ) ;
13+
14+ ( async ( ) => {
15+ try {
16+ if ( firstVisit ) {
17+ await fetch ( `${ ENDPOINT } /up` , { cache : "no-store" , mode : "cors" } ) ;
18+ sessionStorage . setItem ( SESSION_KEY , "1" ) ;
19+ }
20+ const r = await fetch ( `${ ENDPOINT } ` , { cache : "no-store" , mode : "cors" } ) ;
21+ const { value = 0 } = await r . json ( ) ;
22+ render ( value ) ;
23+ } catch ( e ) { console . error ( e ) ; }
24+ } ) ( ) ;
25+ </ script >
26+
27+ < style >
28+ .odometer {
29+ display : inline-block;
30+ font : 700 24 px/1.2 "Courier New" , monospace;
31+ letter-spacing : 2px ;
32+ padding : 6px 10px ;
33+ background : # 111 ; color : # 0f0 ;
34+ border : 3px ridge # c0c0c0 ;
35+ box-shadow : inset 0 0 6px # 090, 0 0 6px # 090 ;
36+ }
37+ </ style >
You can’t perform that action at this time.
0 commit comments