-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.html
More file actions
484 lines (418 loc) · 15 KB
/
index.html
File metadata and controls
484 lines (418 loc) · 15 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
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<title>AI Email Refiner</title>
<link rel="icon" type="image/x-icon" href="logo/logo.png">
<meta name="description"
content="AI-powered email rewriting tool paste an email, choose tone, get polished variations." />
<style>
/* Unique polished dark glass layout, single-file (HTML/CSS/JS only) */
:root {
--bg-0: #061018;
--bg-1: linear-gradient(180deg, #061018 0%, #071827 100%);
--card: rgba(255, 255, 255, 0.03);
--muted: #98a3b3;
--text: #e8f1f8;
--accent: #5eead4;
/* mint */
--accent-2: #60a5fa;
/* blue */
--danger: #fb7185;
--glass-blur: 8px;
--radius: 12px;
--shadow: 0 8px 30px rgba(2, 6, 23, 0.6);
--max-width: 1180px;
}
* {
box-sizing: border-box
}
html,
body {
height: 100%
}
body {
margin: 0;
padding: 28px;
background: var(--bg-1);
color: var(--text);
font-family: Inter, Segoe UI, system-ui, -apple-system, Arial;
display: flex;
justify-content: center;
align-items: flex-start;
min-height: 100vh;
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
.wrap {
width: 100%;
max-width: var(--max-width)
}
header {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 18px
}
.brand {
display: flex;
gap: 12px;
align-items: center
}
.logo {
width: 44px;
height: 44px;
border-radius: 10px;
background: linear-gradient(135deg, var(--accent-2), var(--accent));
display: flex;
align-items: center;
justify-content: center;
color: #012;
font-weight: 800
}
.title {
font-size: 1.1rem;
font-weight: 700
}
.subtitle {
color: var(--muted);
font-size: 0.88rem
}
main {
display: grid;
grid-template-columns: 1fr 420px;
gap: 20px
}
.panel {
background: var(--card);
backdrop-filter: blur(var(--glass-blur));
padding: 18px;
border-radius: var(--radius);
box-shadow: var(--shadow);
}
/* Composer */
.composer {
display: flex;
flex-direction: column;
gap: 12px
}
label {
font-size: 0.85rem;
color: var(--muted);
display: block;
margin-bottom: 6px
}
input[type="text"],
textarea {
width: 100%;
padding: 12px;
border-radius: 10px;
border: 1px solid rgba(255, 255, 255, 0.04);
background: transparent;
color: var(--text);
font-size: 0.98rem
}
textarea {
min-height: 220px;
resize: vertical
}
.row {
display: flex;
gap: 10px;
align-items: center
}
.tone-chips {
display: flex;
gap: 8px;
flex-wrap: wrap
}
.chip {
padding: 8px 12px;
border-radius: 999px;
background: transparent;
border: 1px solid rgba(255, 255, 255, 0.03);
color: var(--muted);
cursor: pointer;
transition: all .15s
}
.chip.active {
background: linear-gradient(90deg, rgba(94, 234, 212, 0.12), rgba(96, 165, 250, 0.08));
color: var(--text);
border-color: rgba(94, 234, 212, 0.2);
transform: translateY(-2px)
}
.controls {
display: flex;
gap: 10px;
align-items: center;
margin-top: 6px
}
.btn {
background: linear-gradient(90deg, var(--accent), var(--accent-2));
border: none;
color: #022;
padding: 10px 14px;
border-radius: 10px;
font-weight: 700;
cursor: pointer
}
.btn.ghost {
background: transparent;
border: 1px solid rgba(255, 255, 255, 0.04);
color: var(--muted);
font-weight: 600
}
.btn:disabled {
opacity: 0.45;
cursor: not-allowed;
transform: none
}
/* Right column */
.right-head {
display: flex;
justify-content: space-between;
align-items: center;
margin-bottom: 10px
}
.status {
color: var(--muted);
font-size: 0.88rem
}
.results {
display: flex;
flex-direction: column;
gap: 12px
}
.result-card {
padding: 12px;
border-radius: 10px;
background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.04));
border: 1px solid rgba(255, 255, 255, 0.02)
}
.result-meta {
display: flex;
justify-content: space-between;
align-items: center;
color: var(--muted);
font-size: 0.85rem
}
.result-text {
margin-top: 8px;
white-space: pre-wrap;
color: var(--text)
}
.history-list {
display: flex;
flex-direction: column;
gap: 8px;
margin-top: 12px
}
.hist-item {
font-size: 0.86rem;
color: var(--muted);
padding: 8px;
border-radius: 8px;
background: rgba(255, 255, 255, 0.01)
}
/* Floating examples card */
.examples {
position: fixed;
right: 28px;
bottom: 28px;
background: linear-gradient(180deg, rgba(255, 255, 255, 0.02), rgba(0, 0, 0, 0.04));
padding: 12px;
border-radius: 12px;
border: 1px solid rgba(255, 255, 255, 0.03);
max-width: 300px
}
/* small screens */
@media (max-width:980px) {
main {
grid-template-columns: 1fr;
}
.examples {
right: 12px;
left: 12px
}
textarea {
min-height: 160px
}
}
/* focus styles for accessibility */
.chip:focus,
.btn:focus,
input:focus,
textarea:focus {
outline: 2px solid rgba(96, 165, 250, 0.18);
outline-offset: 2px
}
</style>
</head>
<body>
<div class="wrap">
<header>
<div class="brand">
<div class="logo">Ai</div>
<div>
<div class="title">AI Email Refiner</div>
<div class="subtitle">Paste an email, pick a voice, get polished variations instantly</div>
</div>
</div>
<!--<div class="small" style="color:var(--muted)">Local demo • HTML / CSS / JS</div>-->
</header>
<main>
<section class="panel composer" aria-labelledby="composer-title">
<h2 id="composer-title" style="margin:0 0 6px 0">Compose</h2>
<div>
<label for="subject">Subject</label>
<input id="subject" type="text" placeholder="Quick project update" />
</div>
<div>
<label for="body">Email body</label>
<textarea id="body" placeholder="Write or paste the email you want rewritten..."></textarea>
</div>
<div class="row">
<div style="flex:1">
<label>Tone</label>
<div class="tone-chips" role="radiogroup" aria-label="Tone selector">
<button class="chip active" data-tone="formal" aria-pressed="true">Formal</button>
<button class="chip" data-tone="friendly">Friendly</button>
<button class="chip" data-tone="assertive">Assertive</button>
</div>
<div id="toneDesc" style="margin-top:8px;color:var(--muted);font-size:0.92rem">Formal: Professional and
polite, suitable for business or official communication.</div>
</div>
<div style="width:180px;text-align:right">
<label style="visibility:hidden">placeholder</label>
<div class="controls">
<button id="rewriteBtn" class="btn" disabled>Refine</button>
<button id="clearBtn" class="btn ghost">Clear</button>
</div>
</div>
</div>
<div style="color:var(--muted);font-size:0.9rem">Tip: Try the "Concise" tone for short, punchy replies, or
"Professional" for formal edits.</div>
</section>
<aside class="panel" aria-live="polite">
<div class="right-head">
<div><strong>Rewrites</strong></div>
<div class="status" id="status">No requests yet</div>
</div>
<div class="results" id="results"></div>
<hr style="border:none;height:1px;margin:12px 0;background:rgba(255,255,255,0.03)">
<div>
<div style="display:flex;justify-content:space-between;align-items:center"><strong>History</strong><button
id="clearHistory" class="btn ghost">Clear</button></div>
<div class="history-list" id="history"></div>
</div>
</aside>
</main>
<!-- <div class="examples panel" aria-hidden="false">
<div style="font-weight:700;margin-bottom:6px">Quick examples</div>
<div style="font-size:0.92rem;color:var(--muted);display:flex;flex-direction:column;gap:6px">
<button class="chip" data-example="followup">Follow up on meeting</button>
<button class="chip" data-example="thanks">Short thank you</button>
<button class="chip" data-example="escalation">Escalation (firm)</button>
</div>
</div>-->
</div>
<script>
// Minimal behaviour: tone chips, rewrite action (fake) and history. Replace fakeRewrite with your API call.
const subject = document.getElementById('subject');
const body = document.getElementById('body');
const rewriteBtn = document.getElementById('rewriteBtn');
const clearBtn = document.getElementById('clearBtn');
const results = document.getElementById('results');
const status = document.getElementById('status');
const historyEl = document.getElementById('history');
const clearHistoryBtn = document.getElementById('clearHistory');
// tone chips and descriptions
const toneDescriptions = {
formal: 'Formal: Professional and polite, suitable for business or official communication.',
friendly: 'Friendly: Warm yet professional, ideal for colleagues or informal business settings.',
assertive: 'Assertive: Direct and confident, useful for urgent or firm requests.'
};
// default tone
let selectedTone = 'formal';
const toneDescEl = document.getElementById('toneDesc');
document.querySelectorAll('.chip[data-tone]').forEach(btn => {
btn.addEventListener('click', () => {
document.querySelectorAll('.chip[data-tone]').forEach(c => { c.classList.remove('active'); c.setAttribute('aria-pressed', 'false') });
btn.classList.add('active'); btn.setAttribute('aria-pressed', 'true');
selectedTone = btn.dataset.tone;
if (toneDescEl) toneDescEl.textContent = toneDescriptions[selectedTone] || '';
});
});
function updateButtons() { rewriteBtn.disabled = body.value.trim().length === 0 && subject.value.trim().length === 0; }
subject.addEventListener('input', updateButtons);
body.addEventListener('input', updateButtons);
clearBtn.addEventListener('click', () => { subject.value = ''; body.value = ''; updateButtons(); results.innerHTML = ''; status.textContent = 'Cleared'; });
clearHistoryBtn.addEventListener('click', () => { localStorage.removeItem('ae_history'); renderHistory(); status.textContent = 'History cleared' });
function renderHistory() {
const items = JSON.parse(localStorage.getItem('ae_history') || '[]');
if (!items.length) { historyEl.innerHTML = '<div style="color:var(--muted)">No history yet</div>'; return }
historyEl.innerHTML = items.slice().reverse().map(it => `<div class="hist-item" title="${new Date(it.t).toLocaleString()}">${escapeHtml(it.summary)}</div>`).join('');
}
renderHistory();
// Quick examples
document.querySelectorAll('.examples .chip[data-example]').forEach(b => {
b.addEventListener('click', () => {
const ex = b.dataset.example;
if (ex === 'followup') { subject.value = 'Following up on our meeting'; body.value = 'Hi Marta, just following up on items from today\'s meeting. Do you have an update on the deliverables?'; }
if (ex === 'thanks') { subject.value = 'Thanks!'; body.value = 'Hi Sam, thanks for your help today — really appreciate it.' }
if (ex === 'escalation') { subject.value = 'Urgent: unresolved issue'; body.value = 'Hello, we still have an outstanding problem that needs attention. Please advise the next steps by EOD.' }
updateButtons();
});
});
// Rewrite using backend API at http://localhost:5000/rewrite
rewriteBtn.addEventListener('click', async () => {
const payload = { subject: subject.value.trim(), body: body.value.trim(), tone: selectedTone };
status.textContent = 'Thinking...';
rewriteBtn.disabled = true;
results.innerHTML = '<div class="result-card" style="color:var(--muted)">Loading…</div>';
try {
const resp = await fetch('http://localhost:5000/rewrite', {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ text: payload.body, tone: payload.tone })
});
if (!resp.ok) {
// try to parse error message
let errMsg = resp.statusText;
try { const errBody = await resp.json(); if (errBody && errBody.error) errMsg = errBody.error; } catch (e) { }
throw new Error(errMsg || `HTTP ${resp.status}`);
}
const data = await resp.json();
const rewritten = data && (data.rewritten || data.output || data.text) ? (data.rewritten || data.output || data.text) : null;
if (!rewritten) { throw new Error('Invalid response from server'); }
const outputs = Array.isArray(rewritten) ? rewritten : [rewritten];
results.innerHTML = outputs.map((o, i) => `
<article class="result-card" role="article" tabindex="0">
<div class="result-meta">Result ${i + 1} <span>
<button data-copy="${i}" class="btn ghost" style="padding:6px 10px">Copy</button>
</span></div>
<div class="result-text">${escapeHtml(o)}</div>
</article>`).join('');
status.textContent = `Last: ${new Date().toLocaleTimeString()}`;
// copy handlers
const outArr = outputs.slice();
[...results.querySelectorAll('button[data-copy]')].forEach(btn => btn.addEventListener('click', ev => {
const idx = +ev.currentTarget.getAttribute('data-copy');
navigator.clipboard?.writeText(outArr[idx]).then(() => { status.textContent = 'Copied' }, () => { status.textContent = 'Copy failed' });
}));
// save history
const h = JSON.parse(localStorage.getItem('ae_history') || '[]');
h.push({ t: Date.now(), summary: payload.subject || payload.body.slice(0, 90) });
localStorage.setItem('ae_history', JSON.stringify(h.slice(-300)));
renderHistory();
} catch (err) {
console.error(err);
results.innerHTML = `<div class="result-card" style="color:var(--danger)">Error: ${escapeHtml(err.message || 'Request failed')}</div>`;
status.textContent = 'Error';
} finally { rewriteBtn.disabled = false }
});
function escapeHtml(s) { return (s || '').replace(/[&<>"']/g, c => ({ '&': '&', '<': '<', '>': '>', '"': '"', "'": ''' }[c])); }
</script>
</body>
</html>