-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
262 lines (225 loc) · 6.29 KB
/
index.html
File metadata and controls
262 lines (225 loc) · 6.29 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Resource Limit Exceeded Counter</title>
<style>
:root {
--bg: #f7f8fa;
--panel: #ffffff;
--text: #111827;
--muted: #6b7280;
--accent: #0f766e;
--accent-hover: #0d655f;
--danger: #b91c1c;
--danger-hover: #991b1b;
--ring: #99f6e4;
--danger-ring: #fecaca;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
min-height: 100vh;
font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif;
color: var(--text);
background: linear-gradient(160deg, #eef2ff 0%, var(--bg) 45%, #f0fdfa 100%);
display: grid;
place-items: center;
padding: 1.25rem;
}
.card {
width: min(640px, 100%);
background: var(--panel);
border: 1px solid #e5e7eb;
border-radius: 16px;
box-shadow: 0 12px 28px rgba(17, 24, 39, 0.08);
padding: clamp(1.25rem, 3vw, 2rem);
text-align: center;
}
h1 {
margin: 0 0 0.5rem;
letter-spacing: 0.04em;
font-size: clamp(1.25rem, 3.2vw, 2rem);
line-height: 1.2;
text-transform: uppercase;
}
p {
margin: 0;
color: var(--muted);
font-size: 0.95rem;
}
.tally {
margin: 1.4rem 0;
font-size: clamp(3rem, 12vw, 6rem);
line-height: 1;
font-weight: 800;
letter-spacing: 0.04em;
}
.controls {
display: flex;
justify-content: center;
gap: 0.75rem;
flex-wrap: wrap;
margin-top: 1rem;
}
button {
border: none;
border-radius: 12px;
color: #ffffff;
font-size: 1rem;
font-weight: 700;
padding: 0.85rem 1.1rem;
cursor: pointer;
transition: background 140ms ease, transform 140ms ease, opacity 140ms ease;
min-width: 180px;
}
#addButton {
background: var(--accent);
}
#addButton:hover {
background: var(--accent-hover);
transform: translateY(-1px);
}
#subtractButton {
background: var(--danger);
}
#subtractButton:hover {
background: var(--danger-hover);
transform: translateY(-1px);
}
button:active {
transform: translateY(0);
}
button:disabled {
opacity: 0.7;
cursor: not-allowed;
transform: none;
}
#addButton:focus-visible {
outline: 3px solid var(--ring);
outline-offset: 2px;
}
#subtractButton:focus-visible {
outline: 3px solid var(--danger-ring);
outline-offset: 2px;
}
.status {
margin-top: 0.9rem;
min-height: 1.2em;
color: var(--muted);
font-size: 0.9rem;
}
.status.error {
color: var(--danger);
}
</style>
</head>
<body>
<main class="card">
<h1>Resource Limit Exceeded Counter</h1>
<p>Shared tally across all devices that open this site.</p>
<div class="tally" id="tally" aria-live="polite">0</div>
<div class="controls">
<button id="addButton" type="button">Add +1</button>
<button id="subtractButton" type="button">Subtract -1</button>
</div>
<div class="status" id="status" aria-live="polite"></div>
</main>
<script>
const tallyEl = document.getElementById("tally");
const addButton = document.getElementById("addButton");
const subtractButton = document.getElementById("subtractButton");
const statusEl = document.getElementById("status");
const API_BASE = "https://api.counterapi.dev/v1";
const COUNTER_NAMESPACE = "rlec-shared-public";
const COUNTER_NAME = "resource-limit-exceeded";
const COUNTER_BASE_URL = `${API_BASE}/${encodeURIComponent(COUNTER_NAMESPACE)}/${encodeURIComponent(COUNTER_NAME)}/`;
function setStatus(message, isError = false) {
statusEl.textContent = message;
statusEl.classList.toggle("error", isError);
}
function setBusy(isBusy) {
addButton.disabled = isBusy;
subtractButton.disabled = isBusy;
}
function setTally(value) {
tallyEl.textContent = String(value);
}
function readCount(data) {
const raw = data && (data.count ?? data.Count);
const count = Number(raw);
if (!Number.isFinite(count)) {
throw new Error("Invalid count payload");
}
return count;
}
async function requestCount(endpoint = "") {
const url = endpoint ? `${COUNTER_BASE_URL}${endpoint}` : COUNTER_BASE_URL;
const response = await fetch(url, { method: "GET", cache: "no-store" });
const payload = await response.json().catch(() => ({}));
if (!response.ok) {
const err = new Error(`Counter API request failed (${response.status})`);
err.status = response.status;
throw err;
}
return readCount(payload);
}
async function loadCount() {
try {
return await requestCount();
} catch (error) {
if (error && error.status === 404) {
try {
return await requestCount("set?count=0");
} catch {
await requestCount("up");
return await requestCount("down");
}
}
throw error;
}
}
async function updateCount(direction) {
setBusy(true);
setStatus("Updating...");
try {
const endpoint = direction === "up" ? "up" : "down";
const count = await requestCount(endpoint);
setTally(count);
setStatus("Updated");
} catch {
setStatus("Could not reach the shared counter. Try again.", true);
} finally {
setBusy(false);
}
}
addButton.addEventListener("click", () => updateCount("up"));
subtractButton.addEventListener("click", () => updateCount("down"));
async function initialLoad() {
setBusy(true);
setStatus("Loading...");
try {
const count = await loadCount();
setTally(count);
setStatus("");
} catch {
setStatus("Could not load shared tally. Check internet connection.", true);
} finally {
setBusy(false);
}
}
initialLoad();
setInterval(async () => {
try {
const count = await requestCount();
setTally(count);
} catch {
// Keep current tally on transient failures.
}
}, 3000);
</script>
</body>
</html>