Skip to content

Commit 4a0d086

Browse files
authored
Add files via upload
1 parent eb157ac commit 4a0d086

1 file changed

Lines changed: 37 additions & 0 deletions

File tree

misc/counter-example.html

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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 24px/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>

0 commit comments

Comments
 (0)