-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchrome-prompt-api.html
More file actions
548 lines (474 loc) · 15.5 KB
/
Copy pathchrome-prompt-api.html
File metadata and controls
548 lines (474 loc) · 15.5 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
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Chrome Prompt API | tools.eliana.lol</title>
<link rel="stylesheet" href="global.css" />
<link rel="icon" type="image/x-icon" href="favicon.svg" />
<style>
.container {
display: flex;
flex-direction: column;
gap: 1.5rem;
}
.panel {
display: flex;
flex-direction: column;
gap: 1rem;
padding: 1rem;
border: 1px solid var(--puny);
background-color: var(--highlight);
border-radius: 4px;
}
.panel-title {
font-weight: bold;
text-transform: uppercase;
color: var(--accent);
font-size: 0.95rem;
}
.input-group {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.input-label {
font-size: 0.85rem;
font-weight: bold;
text-transform: uppercase;
color: var(--puny);
letter-spacing: 0.05em;
}
select,
textarea {
width: 100%;
font-family: monospace;
padding: 10px;
border: 1px solid var(--puny);
background: var(--bg);
color: var(--text);
box-sizing: border-box;
border-radius: 4px;
font-size: 0.95rem;
}
select:focus,
textarea:focus {
outline: none;
border-color: var(--accent);
}
textarea {
min-height: 150px;
resize: vertical;
}
.button-group {
display: flex;
flex-wrap: wrap;
gap: 0.75rem;
}
button {
flex: 0 1 auto;
min-width: 120px;
padding: 10px;
cursor: pointer;
font-family: monospace;
border: 1px solid var(--text);
background: var(--bg);
color: var(--text);
border-radius: 4px;
transition: all 150ms;
}
button:hover {
background-color: var(--hover);
border-color: var(--accent);
}
button.primary {
border-color: var(--accent);
font-weight: bold;
color: var(--accent);
}
button:disabled {
opacity: 0.5;
cursor: not-allowed;
}
.response-area {
width: 100%;
font-family: monospace;
padding: 10px;
border: 1px solid var(--puny);
background: var(--bg);
color: var(--text);
box-sizing: border-box;
border-radius: 4px;
min-height: 200px;
max-height: 400px;
overflow-y: auto;
white-space: pre-wrap;
word-break: break-word;
}
.stats {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
gap: 1rem;
}
.stat {
text-align: center;
padding: 0.75rem;
border: 1px solid var(--puny);
border-radius: 4px;
background-color: var(--highlight);
}
.stat-value {
font-size: 1.3rem;
font-weight: bold;
color: var(--accent);
line-height: 1;
margin-bottom: 0.25rem;
}
.stat-label {
font-size: 0.75rem;
text-transform: uppercase;
color: var(--puny);
}
.status {
padding: 0.75rem 1rem;
border-radius: 4px;
margin: 0.5rem 0;
display: none;
font-size: 0.9rem;
}
.status.show {
display: block;
}
.status.success {
background-color: rgba(16, 185, 129, 0.1);
border-left: 3px solid var(--accent);
color: var(--accent);
}
.status.error {
background-color: rgba(239, 68, 68, 0.1);
border-left: 3px solid #ef4444;
color: #ef4444;
}
.status.info {
background-color: rgba(59, 130, 246, 0.1);
border-left: 3px solid #3b82f6;
color: #3b82f6;
}
.info-box {
padding: 1rem;
background-color: var(--highlight);
border-left: 3px solid var(--accent);
font-size: 0.9rem;
line-height: 1.6;
}
.status-indicator {
display: inline-block;
width: 10px;
height: 10px;
border-radius: 50%;
margin-right: 8px;
background: #ef4444;
}
.status-indicator.available {
background: #10b981;
}
.feature-list {
display: flex;
flex-direction: column;
gap: 0.5rem;
}
.feature-item {
display: flex;
gap: 0.75rem;
font-size: 0.9rem;
}
.feature-icon {
color: var(--accent);
font-weight: bold;
}
.main-grid {
display: grid;
grid-template-columns: 1fr 1fr;
gap: 1.5rem;
}
@media (max-width: 800px) {
.main-grid {
grid-template-columns: 1fr;
}
.button-group {
flex-direction: column;
}
button {
width: 100%;
}
}
</style>
</head>
<body>
<nav>
<div class="left">
<a href="index.html">home</a> | <a href="extra.html">extra</a> |
<a href="credits.html">credits</a> |
<a href="changelog.html">logs</a>
</div>
<div class="right">
<button id="theme-toggle">[theme]</button> |
<a href="https://eliana.lol">site</a>
</div>
</nav>
<main>
<h1>Chrome Prompt API Test</h1>
<p class="puny">Generate text locally using Gemini Nano in Chrome 123+</p>
<div class="container">
<div class="info-box">
<strong>Status:</strong>
<span class="status-indicator" id="statusIndicator"></span>
<span id="statusText">Checking availability...</span>
<div id="statusDetail" style="font-size: 0.85rem; margin-top: 0.5rem; color: var(--puny)"></div>
</div>
<div class="main-grid">
<div class="panel">
<div class="panel-title">⚙️ Configuration</div>
<div class="input-group">
<label class="input-label" for="taskType">Task Type:</label>
<select id="taskType">
<option value="writing">Writing</option>
<option value="creative">Creative Writing</option>
<option value="code">Code Generation</option>
<option value="analysis">Analysis</option>
</select>
</div>
<div class="input-group">
<label class="input-label" for="tone">Tone:</label>
<select id="tone">
<option value="neutral">Neutral</option>
<option value="formal">Formal</option>
<option value="casual">Casual</option>
<option value="technical">Technical</option>
</select>
</div>
<div class="input-group">
<label class="input-label" for="maxTokens">Max Tokens:</label>
<select id="maxTokens">
<option value="256">256</option>
<option value="512" selected>512</option>
<option value="1024">1024</option>
</select>
</div>
<div class="input-group">
<label class="input-label" for="temperature">Temperature:</label>
<select id="temperature">
<option value="0.2">0.2 (Deterministic)</option>
<option value="0.5">0.5 (Balanced)</option>
<option value="0.7" selected>0.7 (Varied)</option>
<option value="1.0">1.0 (Creative)</option>
</select>
</div>
<div class="input-group">
<label class="input-label" for="prompt">Your Prompt:</label>
<textarea id="prompt" placeholder="Enter your prompt here...">Write a short poem about artificial intelligence.</textarea>
</div>
<div class="button-group">
<button id="generateBtn" class="primary" onclick="generateText()" disabled>
Generate
</button>
<button onclick="clearForm()">Clear</button>
</div>
<div class="feature-list">
<div style="font-weight: bold; color: var(--accent); margin-top: 1rem;">Features:</div>
<div class="feature-item">
<span class="feature-icon">✓</span>
<span>Runs locally on your device</span>
</div>
<div class="feature-item">
<span class="feature-icon">✓</span>
<span>No server communication</span>
</div>
<div class="feature-item">
<span class="feature-icon">✓</span>
<span>Complete privacy</span>
</div>
<div class="feature-item">
<span class="feature-icon">✓</span>
<span>Powered by Gemini Nano</span>
</div>
</div>
</div>
<div class="panel">
<div class="panel-title">📤 Response Output</div>
<div class="status" id="status"></div>
<div class="response-area" id="responseArea">
Generated text will appear here...
</div>
<div class="stats" id="stats" style="display: none;">
<div class="stat">
<div class="stat-value" id="tokenCount">0</div>
<div class="stat-label">Tokens</div>
</div>
<div class="stat">
<div class="stat-value" id="timeMs">0ms</div>
<div class="stat-label">Time</div>
</div>
<div class="stat">
<div class="stat-value" id="charCount">0</div>
<div class="stat-label">Chars</div>
</div>
</div>
<div class="button-group" style="margin-top: 1rem;">
<button onclick="copyResponse()">Copy</button>
<button onclick="downloadResponse()">Download</button>
</div>
</div>
</div>
</div>
</main>
<footer style="margin-top: 4rem; text-align: center" class="puny">
© 2026 eliana.lol • <a href="credits.html">credits</a>
</footer>
<!-- Theme Toggle Script (Required for all tools) -->
<script>
const html = document.documentElement;
const toggle = document.getElementById('theme-toggle');
const saved =
localStorage.getItem('theme') ||
(window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light');
html.setAttribute('data-theme', saved);
if (toggle) toggle.innerText = saved === 'dark' ? '[light]' : '[dark]';
if (toggle) {
toggle.onclick = () => {
const now = html.getAttribute('data-theme');
const next = now === 'dark' ? 'light' : 'dark';
html.setAttribute('data-theme', next);
localStorage.setItem('theme', next);
toggle.innerText = next === 'dark' ? '[light]' : '[dark]';
};
}
</script>
<!-- Tool-specific script -->
<script>
const generateBtn = document.getElementById('generateBtn');
const responseArea = document.getElementById('responseArea');
const status = document.getElementById('status');
const statusIndicator = document.getElementById('statusIndicator');
const statusText = document.getElementById('statusText');
const statusDetail = document.getElementById('statusDetail');
let apiAvailable = false;
let model = null;
// Check if API is available
async function checkAPI() {
if (!('ai' in window)) {
showStatus('error', '❌ Prompt API not available in this browser');
statusIndicator.classList.remove('available');
statusText.textContent = 'Prompt API Not Available';
statusDetail.textContent = 'This feature requires Chrome 123+ with the Generative AI API origin trial enabled.';
return;
}
try {
const canCreate = await window.ai.languageModel.canCreateTextSession();
if (canCreate === 'readily' || canCreate === 'after-download') {
apiAvailable = true;
generateBtn.disabled = false;
statusIndicator.classList.add('available');
statusText.textContent = '✅ Chrome Prompt API Available';
statusDetail.textContent = 'Gemini Nano is ready to use on your device!';
// Load model
try {
model = await window.ai.languageModel.create();
console.log('Model loaded successfully');
} catch (err) {
console.error('Error loading model:', err);
}
} else {
showStatus('info', '⏳ Model needs to be downloaded first. Try again in a moment.');
statusText.textContent = 'Model Downloading';
statusDetail.textContent = 'The Gemini Nano model is being prepared for your device.';
}
} catch (err) {
console.error('Error checking API:', err);
showStatus('error', '❌ Error checking API availability');
}
}
async function generateText() {
if (!apiAvailable || !model) {
showStatus('error', '❌ API not ready. Please wait and try again.');
return;
}
const taskType = document.getElementById('taskType').value;
const tone = document.getElementById('tone').value;
const maxTokens = parseInt(document.getElementById('maxTokens').value);
const temperature = parseFloat(document.getElementById('temperature').value);
const prompt = document.getElementById('prompt').value;
if (!prompt.trim()) {
showStatus('error', '❌ Please enter a prompt');
return;
}
generateBtn.disabled = true;
responseArea.textContent = '';
showStatus('info', '⏳ Generating response...');
const startTime = performance.now();
try {
let fullPrompt = prompt;
// Add context based on task type
if (taskType !== 'writing') {
fullPrompt = `As a ${taskType} assistant with a ${tone} tone, please: ${prompt}`;
}
const response = await model.generateContent(fullPrompt);
const endTime = performance.now();
const timeTaken = endTime - startTime;
responseArea.textContent = response;
// Update stats
const chars = response.length;
const estimatedTokens = Math.ceil(chars / 4);
document.getElementById('tokenCount').textContent = estimatedTokens;
document.getElementById('timeMs').textContent = Math.round(timeTaken) + 'ms';
document.getElementById('charCount').textContent = chars;
document.getElementById('stats').style.display = 'grid';
showStatus('success', '✅ Response generated successfully!');
} catch (error) {
console.error('Generation error:', error);
showStatus('error', '❌ Error: ' + error.message);
responseArea.textContent = '';
} finally {
generateBtn.disabled = false;
}
}
function copyResponse() {
const text = responseArea.textContent;
if (text && text !== 'Generated text will appear here...') {
navigator.clipboard.writeText(text);
showStatus('success', '✅ Response copied to clipboard!');
}
}
function downloadResponse() {
const text = responseArea.textContent;
if (text && text !== 'Generated text will appear here...') {
const blob = new Blob([text], { type: 'text/plain' });
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = 'response-' + Date.now() + '.txt';
a.click();
}
}
function clearForm() {
document.getElementById('prompt').value = '';
responseArea.textContent = 'Generated text will appear here...';
document.getElementById('stats').style.display = 'none';
showStatus('', '');
}
function showStatus(type, message) {
if (!message) {
status.style.display = 'none';
return;
}
status.className = 'status show ' + type;
status.textContent = message;
status.style.display = 'block';
}
// Initialize on load
window.addEventListener('load', checkAPI);
// Check again periodically
setInterval(checkAPI, 5000);
</script>
</body>
</html>