-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweb-demo.html
More file actions
338 lines (299 loc) · 10.6 KB
/
web-demo.html
File metadata and controls
338 lines (299 loc) · 10.6 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
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>ZeroCarbon API - Interactive Demo</title>
<style>
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
padding: 20px;
}
.container {
background: white;
border-radius: 16px;
box-shadow: 0 20px 60px rgba(0,0,0,0.3);
max-width: 600px;
width: 100%;
padding: 40px;
}
h1 {
font-size: 28px;
color: #1a202c;
margin-bottom: 8px;
}
.subtitle {
color: #718096;
margin-bottom: 32px;
}
.demo-section {
margin-bottom: 24px;
padding: 20px;
background: #f7fafc;
border-radius: 8px;
border-left: 4px solid #667eea;
}
.demo-title {
font-size: 18px;
font-weight: 600;
color: #2d3748;
margin-bottom: 12px;
display: flex;
align-items: center;
gap: 8px;
}
.demo-description {
color: #718096;
margin-bottom: 16px;
font-size: 14px;
}
button {
background: #667eea;
color: white;
border: none;
padding: 12px 24px;
border-radius: 8px;
font-size: 14px;
font-weight: 600;
cursor: pointer;
transition: all 0.2s;
}
button:hover {
background: #5a67d8;
transform: translateY(-1px);
box-shadow: 0 4px 12px rgba(102, 126, 234, 0.4);
}
:disabled {
background: #cbd5e0;
cursor: not-allowed;
transform: none;
}
.result {
margin-top: 16px;
padding: 16px;
background: white;
border-radius: 6px;
border: 1px solid #e2e8f0;
display: none;
}
.result.show {
display: block;
animation: slideIn 0.3s ease;
}
@keyframes slideIn {
from {
opacity: 0;
transform: translateY(-10px);
}
to {
opacity: 1;
transform: translateY(0);
}
}
.result-value {
font-size: 24px;
font-weight: 700;
color: #10b981;
margin-bottom: 8px;
}
.result-detail {
color: #64748b;
font-size: 13px;
margin-top: 4px;
}
.code-block {
background: #1a202c;
color: #e2e8f0;
padding: 16px;
border-radius: 6px;
font-family: 'Monaco', 'Courier New', monospace;
font-size: 12px;
overflow-x: auto;
margin-top: 24px;
}
.next-steps {
margin-top: 32px;
padding: 20px;
background: #edf2f7;
border-radius: 8px;
}
.next-steps h3 {
font-size: 16px;
color: #2d3748;
margin-bottom: 12px;
}
.next-steps a {
display: block;
color: #667eea;
text-decoration: none;
margin: 8px 0;
font-size: 14px;
}
.next-steps a:hover {
text-decoration: underline;
}
.loading {
display: inline-block;
width: 14px;
height: 14px;
border: 2px solid rgba(255, 255, 255, 0.3);
border-top-color: white;
border-radius: 50%;
animation: spin 0.8s linear infinite;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
</style>
</head>
<body>
<div class="container">
<h1>⚡ ZeroCarbon API Demo</h1>
<p class="subtitle">Calculate carbon emissions in real-time. No signup required.</p>
<div class="demo-section">
<div class="demo-title">🔌 Electricity Emissions</div>
<div class="demo-description">Calculate emissions from 1,000 kWh of U.S. electricity</div>
<button onclick="demoElectricity(this)">Run Demo</button>
<div class="result" id="result-electricity">
<div class="result-value"></div>
<div class="result-detail"></div>
</div>
</div>
<div class="demo-section">
<div class="demo-title">✈️ Flight Emissions</div>
<div class="demo-description">Calculate emissions for SFO → JFK economy flight</div>
<button onclick="demoFlight(this)">Run Demo</button>
<div class="result" id="result-flight">
<div class="result-value"></div>
<div class="result-detail"></div>
</div>
</div>
<div class="demo-section">
<div class="demo-title">🚗 Vehicle Emissions</div>
<div class="demo-description">Calculate emissions for 100 miles of driving</div>
<button onclick="demoVehicle(this)">Run Demo</button>
<div class="result" id="result-vehicle">
<div class="result-value"></div>
<div class="result-detail"></div>
</div>
</div>
<div class="code-block">
// It's this easy:<br>
const response = await fetch('https://api.zerocarbon.codes/v1/emissions/calculate', {<br>
method: 'POST',<br>
body: JSON.stringify({<br>
source: 'electricity',<br>
value: 1000,<br>
unit: 'kWh',<br>
country: 'US'<br>
})<br>
});
</div>
<div class="next-steps">
<h3>🚀 Ready to integrate?</h3>
<a href="https://app.zerocarbon.codes/signup" target="_blank">→ Get Free API Key (30 seconds)</a>
<a href="https://docs.zerocarbon.codes" target="_blank">→ View Full Documentation</a>
<a href="https://github.com/zerocarbon/examples" target="_blank">→ See Example Applications</a>
</div>
</div>
<script>
// Auto-detect API base URL
const API_BASE = window.location.hostname === 'localhost'
? 'http://localhost:3000/api'
: 'https://zerocarbon.codes/api';
async function apiRequest(endpoint, data) {
const response = await fetch(`${API_BASE}${endpoint}`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify(data)
});
return response.json();
}
function showResult(id, value, detail) {
const result = document.getElementById(id);
result.querySelector('.result-value').textContent = value;
result.querySelector('.result-detail').textContent = detail;
result.classList.add('show');
}
async function demoElectricity(button) {
button.disabled = true;
button.innerHTML = '<span class="loading"></span>';
try {
const result = await apiRequest('/v1/emissions/calculate', {
source: 'electricity',
value: 1000,
unit: 'kWh',
country: 'US'
});
if (result.success) {
const emissions = result.data.emissions_kg_co2e;
showResult(
'result-electricity',
`${emissions} kg CO2e`,
`Equivalent to ${(emissions / 411).toFixed(1)} gallons of gasoline`
);
}
} catch (error) {
showResult('result-electricity', 'Error', error.message);
} finally {
button.disabled = false;
button.textContent = 'Run Demo';
}
}
async function demoFlight(button) {
button.disabled = true;
button.innerHTML = '<span class="loading"></span>';
try {
const result = await apiRequest('/v1/calculate/flight', {
from: 'SFO',
to: 'JFK',
passengers: 1,
class: 'economy'
});
if (result.success) {
showResult(
'result-flight',
`${result.data.emissions_kg_co2e} kg CO2e`,
`Distance: ${result.data.distance_km} km • Per passenger`
);
}
} catch (error) {
showResult('result-flight', 'Error', error.message);
} finally {
button.disabled = false;
button.textContent = 'Run Demo';
}
}
async function demoVehicle(button) {
button.disabled = true;
button.innerHTML = '<span class="loading"></span>';
try {
const result = await apiRequest('/v1/calculate/fuel', {
fuel_type: 'gasoline',
distance: 100,
unit: 'miles',
vehicle_type: 'car'
});
if (result.success) {
showResult(
'result-vehicle',
`${result.data.emissions_kg_co2e} kg CO2e`,
`Fuel consumed: ${result.data.fuel_consumed_liters.toFixed(2)} liters`
);
}
} catch (error) {
showResult('result-vehicle', 'Error', error.message);
} finally {
button.disabled = false;
button.textContent = 'Run Demo';
}
}
</script>
</body>
</html>