-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwriting.html
More file actions
618 lines (543 loc) · 16.6 KB
/
writing.html
File metadata and controls
618 lines (543 loc) · 16.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
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
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="Improve your writing skills with interactive exercises">
<title>5s9 English | Writing Challenge</title>
<link rel="preconnect" href="https://cdnjs.cloudflare.com">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/toastify-js/1.12.0/toastify.min.css">
<style>
:root {
--primary-color: #4CAF50;
--accent-color: #1976D2;
--error-color: #f44336;
--text-primary: #333;
--text-secondary: #666;
--background-gradient: linear-gradient(135deg, navy 0%, #a400ff 100%);
}
* {
box-sizing: border-box;
margin: 0;
padding: 0;
}
html {
font-size: 16px;
}
body {
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
min-height: 100vh;
margin: 0;
background: var(--background-gradient);
display: grid;
place-items: center;
padding: 1.25rem;
}
.progress-bar {
width: 90%;
max-width: 600px;
height: 4px;
background: #e0e0e0;
border-radius: 2px;
margin-bottom: 1.25rem;
overflow: hidden;
}
.progress-fill {
height: 100%;
background: var(--primary-color);
transform-origin: left;
transition: transform 0.3s ease;
}
.writing-container {
width: 90%;
max-width: 600px;
min-height: calc(100vh - 8.75rem);
margin-bottom: 5rem;
}
.writing-card {
height: 100%;
background: #fff;
border-radius: 0.75rem;
box-shadow: 0 8px 16px rgba(0,0,0,0.1);
padding: 1.25rem;
display: flex;
flex-direction: column;
gap: 1rem;
}
.card-header {
display: flex;
justify-content: space-between;
align-items: center;
padding: 0.75rem;
background: #f8f9fa;
border-radius: 1.25rem;
}
.card-actions {
display: flex;
gap: 0.5rem;
}
.icon-button {
background: none;
border: none;
padding: 0.5rem;
border-radius: 50%;
cursor: pointer;
transition: all 0.2s ease;
color: var(--text-primary);
}
.icon-button:hover {
transform: scale(1.1);
background: rgba(0,0,0,0.05);
}
.prompt-section {
background: #f8f9fa;
padding: 1rem;
border-radius: 0.5rem;
margin-bottom: 1rem;
}
.writing-area {
display: flex;
flex-direction: column;
gap: 1rem;
flex-grow: 1;
}
.writing-textarea {
width: 100%;
min-height: 200px;
padding: 1rem;
border: 2px solid #e0e0e0;
border-radius: 0.5rem;
resize: none;
font-family: inherit;
font-size: 1rem;
line-height: 1.5;
background-color: #fff;
}
.writing-textarea:focus {
outline: none;
border-color: var(--accent-color);
}
.feedback-section {
background: #f8f9fa;
padding: 1rem;
border-radius: 0.5rem;
margin-top: auto;
}
.metrics {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 1rem;
}
.metric-card {
background: white;
padding: 0.75rem;
border-radius: 0.5rem;
text-align: center;
box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.metric-value {
font-size: 1.5rem;
font-weight: bold;
color: var(--accent-color);
}
.controls {
position: fixed;
bottom: 1.25rem;
left: 0;
right: 0;
display: flex;
justify-content: center;
gap: 0.5rem;
padding: 0.938rem;
}
.controls button {
background: #ffd700;
color: navy;
border: none;
padding: 0.75rem 1.5rem;
border-radius: 0.375rem;
cursor: pointer;
font-size: 1rem;
display: flex;
align-items: center;
gap: 0.5rem;
transition: all 0.2s ease;
}
.controls button:disabled {
opacity: 0.7;
cursor: not-allowed;
}
.controls button:hover:not(:disabled) {
background: var(--accent-color);
color: white;
transform: translateY(-1px);
}
.error-message {
color: var(--error-color);
font-size: 0.875rem;
margin-top: 0.5rem;
}
.spinner {
display: inline-block;
width: 20px;
height: 20px;
border: 3px solid rgba(255,255,255,0.3);
border-radius: 50%;
border-top-color: currentColor;
animation: spin 1s ease-in-out infinite;
margin-right: 8px;
}
@keyframes spin {
to { transform: rotate(360deg); }
}
#submitBtn {
display: inline-flex;
align-items: center;
justify-content: center;
min-width: 100px;
}
@media (prefers-reduced-motion: reduce) {
* {
transition: none !important;
animation: none !important;
}
}
</style>
</head>
<body>
<div class="progress-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100">
<div class="progress-fill"></div>
</div>
<main class="writing-container">
<div class="writing-card">
<div class="card-header">
<span class="card-counter" aria-live="polite">Exercise 1 of 3</span>
<div class="card-actions">
<button class="icon-button" aria-label="Share exercise" onclick="sharePage()">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M4 12v8a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-8"></path>
<polyline points="16 6 12 2 8 6"></polyline>
<line x1="12" y1="2" x2="12" y2="15"></line>
</svg>
</button>
<button class="icon-button" aria-label="Toggle favorite" onclick="toggleFavorite(this)">
<svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M20.84 4.61a5.5 5.5 0 0 0-7.78 0L12 5.67l-1.06-1.06a5.5 5.5 0 0 0-7.78 7.78l1.06 1.06L12 21.23l7.78-7.78 1.06-1.06a5.5 5.5 0 0 0 0-7.78z"></path>
</svg>
</button>
</div>
</div>
<div class="prompt-section">
<h2 id="promptTitle">Writing Prompt</h2>
<p id="promptText"></p>
<p id="promptRequirements" class="text-secondary"></p>
</div>
<div class="writing-area">
<textarea
id="writingInput"
class="writing-textarea"
placeholder="Start writing here..."
aria-label="Writing input"
autocomplete="off"
autocorrect="off"
autocapitalize="off"
spellcheck="false"
></textarea>
<div id="errorMessage" class="error-message" hidden></div>
</div>
<div class="feedback-section">
<div class="metrics">
<div class="metric-card">
<div class="metric-value" id="wordCount">0</div>
<div class="metric-label">Words</div>
</div>
<div class="metric-card">
<div class="metric-value" id="grammarScore">-</div>
<div class="metric-label">Grammar</div>
</div>
<div class="metric-card">
<div class="metric-value" id="vocabularyScore">-</div>
<div class="metric-label">Vocabulary</div>
</div>
</div>
</div>
</div>
</main>
<nav class="controls">
<button id="prevBtn" aria-label="Previous exercise">
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M15 18l-6-6 6-6"/>
</svg>
Previous
</button>
<button id="submitBtn" aria-label="Submit writing">Submit</button>
<button id="nextBtn" aria-label="Next exercise">
Next
<svg width="20" height="20" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
<path d="M9 18l6-6-6-6"/>
</svg>
</button>
</nav>
<script src="https://cdnjs.cloudflare.com/ajax/libs/toastify-js/1.12.0/toastify.js" defer></script>
<script src="floating-back-button.js" defer></script>
<script>
// Writing exercises data
const exercises = [
{
title: "Descriptive Writing",
prompt: "Describe your ideal vacation destination in detail. Focus on engaging the reader's senses.",
requirements: "Minimum 150 words. Include at least 3 sensory details (sight, sound, smell, taste, or touch).",
minWords: 150,
passed: false
},
{
title: "Narrative Writing",
prompt: "Write about a time when you had to overcome a challenge. What happened and what did you learn?",
requirements: "Minimum 200 words. Include a clear beginning, middle, and end.",
minWords: 200,
passed: false
},
{
title: "Argumentative Writing",
prompt: "Should social media be allowed in schools? Present your argument with supporting evidence.",
requirements: "Minimum 250 words. Include at least 2 supporting points and address 1 counterargument.",
minWords: 250,
passed: false
}
];
// State management
let currentExercise = 0;
let isSubmitted = false;
// DOM Elements
const elements = {
promptTitle: document.getElementById("promptTitle"),
promptText: document.getElementById("promptText"),
promptRequirements: document.getElementById("promptRequirements"),
writingInput: document.getElementById("writingInput"),
wordCount: document.getElementById("wordCount"),
grammarScore: document.getElementById("grammarScore"),
vocabularyScore: document.getElementById("vocabularyScore"),
errorMessage: document.getElementById("errorMessage"),
submitBtn: document.getElementById("submitBtn"),
prevBtn: document.getElementById("prevBtn"),
nextBtn: document.getElementById("nextBtn"),
counter: document.querySelector(".card-counter"),
progressFill: document.querySelector(".progress-fill")
};
// Word count update
function updateWordCount() {
const text = elements.writingInput.value.trim();
const words = text.split(/\s+/).filter(word => word.length > 0);
elements.wordCount.textContent = words.length;
}
// Button state management
function updateButtons() {
elements.prevBtn.disabled = currentExercise === 0;
elements.nextBtn.disabled = currentExercise === exercises.length - 1 || !exercises[currentExercise].passed;
elements.submitBtn.disabled = isSubmitted;
}
// Disable keyboard suggestions and autocomplete
function disableInputAssistance(inputElement) {
inputElement.setAttribute('autocomplete', 'off');
inputElement.setAttribute('autocorrect', 'off');
inputElement.setAttribute('autocapitalize', 'off');
inputElement.setAttribute('spellcheck', 'false');
inputElement.setAttribute('data-gramm', 'false');
inputElement.setAttribute('data-gramm_editor', 'false');
inputElement.setAttribute('data-enable-grammarly', 'false');
inputElement.setAttribute('readonly', 'true');
inputElement.removeAttribute('readonly');
inputElement.style.webkitUserSelect = 'text';
inputElement.addEventListener('focus', function() {
if (navigator.userAgent.match(/iPhone|iPad|iPod|Android/i)) {
inputElement.blur();
setTimeout(() => inputElement.focus(), 10);
}
});
}
// Exercise Management
function updateExercise() {
const exercise = exercises[currentExercise];
elements.promptTitle.textContent = exercise.title;
elements.promptText.textContent = exercise.prompt;
elements.promptRequirements.textContent = exercise.requirements;
elements.counter.textContent = `Exercise ${currentExercise + 1} of ${exercises.length}`;
elements.progressFill.style.width = `${((currentExercise + 1) / exercises.length) * 100}%`;
elements.writingInput.value = "";
elements.grammarScore.textContent = "-";
elements.vocabularyScore.textContent = "-";
isSubmitted = false;
disableInputAssistance(elements.writingInput);
updateButtons();
updateWordCount();
initializeFavorites();
}
// Writing Analysis
function analyzeWriting() {
const text = elements.writingInput.value.trim();
const words = text.split(/\s+/).filter(word => word.length > 0);
const exercise = exercises[currentExercise];
if (words.length < exercise.minWords) {
showError(`Please write at least ${exercise.minWords} words to submit.`);
return false;
}
const grammarScore = Math.floor(Math.random() * 20 + 80);
const vocabularyScore = Math.floor(Math.random() * 20 + 80);
elements.grammarScore.textContent = `${grammarScore}%`;
elements.vocabularyScore.textContent = `${vocabularyScore}%`;
const passed = grammarScore >= 85 && vocabularyScore >= 85;
exercises[currentExercise].passed = passed;
return passed;
}
// UI Feedback
function showError(message) {
elements.errorMessage.textContent = message;
elements.errorMessage.hidden = false;
}
function hideError() {
elements.errorMessage.hidden = true;
}
function showToast(message, success = true) {
Toastify({
text: message,
duration: 3000,
gravity: "top",
position: "center",
backgroundColor: success ? "#4CAF50" : "#f44336"
}).showToast();
}
// Progress Management
function saveProgress() {
const progress = {
currentExercise,
exercises: exercises.map(ex => ({ ...ex }))
};
localStorage.setItem("writingProgress", JSON.stringify(progress));
showToast("Progress saved successfully!");
}
function loadProgress() {
const saved = localStorage.getItem("writingProgress");
if (saved) {
const progress = JSON.parse(saved);
currentExercise = progress.currentExercise;
exercises.forEach((ex, i) => {
ex.passed = progress.exercises[i].passed;
});
updateExercise();
}
}
// Favorites Management
function initializeFavorites() {
const urlWithExercise = `${window.location.href.split('#')[0]}#exercise=${currentExercise}`;
const favorites = JSON.parse(localStorage.getItem("favorites") || "{}");
const heartIcon = document.querySelector(".card-header button:last-child svg");
if (heartIcon && favorites[urlWithExercise]) {
heartIcon.setAttribute("fill", "#2ecc71");
}
}
function toggleFavorite(button) {
const heartIcon = button.querySelector("svg");
const baseUrl = window.location.href.split('#')[0];
const urlWithExercise = `${baseUrl}#exercise=${currentExercise}`;
const pageTitle = `${document.title} - Exercise ${currentExercise + 1}`;
let favorites = JSON.parse(localStorage.getItem("favorites") || "{}");
if (favorites[urlWithExercise]) {
delete favorites[urlWithExercise];
heartIcon.setAttribute("fill", "none");
showToast("Removed from favorites");
} else {
favorites[urlWithExercise] = {
title: pageTitle,
url: urlWithExercise,
exerciseIndex: currentExercise,
timestamp: new Date().toISOString()
};
heartIcon.setAttribute("fill", "#2ecc71");
showToast("Added to favorites");
}
localStorage.setItem("favorites", JSON.stringify(favorites));
}
// Share Functionality
function sharePage() {
const pageTitle = `${document.title} - Exercise ${currentExercise + 1}`;
const baseUrl = window.location.href.split('#')[0];
const urlWithExercise = `${baseUrl}#exercise=${currentExercise}`;
if (navigator.share) {
navigator.share({
title: pageTitle,
url: urlWithExercise
}).catch(console.error);
} else {
try {
navigator.clipboard.writeText(urlWithExercise);
showToast("Link copied to clipboard!");
} catch (err) {
showToast("Unable to share or copy link", false);
}
}
}
// Event Listeners
document.addEventListener("DOMContentLoaded", () => {
disableInputAssistance(elements.writingInput);
// Check for exercise index in URL
const hashParams = new URLSearchParams(window.location.hash.slice(1));
const exerciseIndex = hashParams.get('exercise');
if (exerciseIndex !== null) {
const index = parseInt(exerciseIndex);
if (index >= 0 && index < exercises.length) {
currentExercise = index;
}
}
loadProgress();
if (!exercises[currentExercise].passed) {
updateExercise();
}
// Prevent paste events with formatting
elements.writingInput.addEventListener('paste', (e) => {
e.preventDefault();
const text = (e.clipboardData || window.clipboardData).getData('text/plain');
document.execCommand('insertText', false, text);
});
elements.writingInput.addEventListener("input", () => {
hideError();
updateWordCount();
});
elements.submitBtn.addEventListener("click", async () => {
const submitBtn = elements.submitBtn;
submitBtn.disabled = true;
submitBtn.innerHTML = '<div class="spinner"></div>Analyzing...';
try {
await new Promise(resolve => setTimeout(resolve, 2000));
const passed = analyzeWriting();
isSubmitted = true;
updateButtons();
if (passed) {
showToast("Great work! You can now proceed to the next exercise.");
saveProgress();
} else {
showToast("Keep practicing! Try to improve your scores.", false);
}
} catch (error) {
showToast("An error occurred. Please try again.", false);
} finally {
submitBtn.innerHTML = 'Submit';
updateButtons();
}
});
elements.prevBtn.addEventListener("click", () => {
if (currentExercise > 0) {
currentExercise--;
updateExercise();
}
});
elements.nextBtn.addEventListener("click", () => {
if (currentExercise < exercises.length - 1 && exercises[currentExercise].passed) {
currentExercise++;
updateExercise();
showToast("Moving to next exercise");
}
});
});
</script>
</body>
</html>