Skip to content

Commit e5c237b

Browse files
committed
- grammar check v0.6
1 parent 36e6b7e commit e5c237b

File tree

1 file changed

+105
-24
lines changed

1 file changed

+105
-24
lines changed

tools/grammar_check.html

Lines changed: 105 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<meta name="viewport" content="width=device-width,initial-scale=1.0">
88
<script src="https://cdn.tailwindcss.com"></script>
99
<script src="https://cdnjs.cloudflare.com/ajax/libs/json5/2.2.3/index.min.js"></script>
10-
<title>GrammarPro</title>
10+
<title>AI Grammar Checker</title>
1111
<style>.error-highlight {
1212
position: relative;
1313
display: inline-block;
@@ -44,26 +44,6 @@
4444
opacity: 1;
4545
}
4646

47-
.loading-dots:after {
48-
content: '.';
49-
animation: dots 1.5s steps(5, end) infinite;
50-
}
51-
52-
@keyframes dots {
53-
0%, 20% {
54-
content: '.';
55-
}
56-
40% {
57-
content: '..';
58-
}
59-
60% {
60-
content: '...';
61-
}
62-
80%, 100% {
63-
content: '';
64-
}
65-
}
66-
6747
#word-count {
6848
transition: all 0.3s ease;
6949
}
@@ -102,8 +82,7 @@
10282
<div class="flex items-center justify-between mb-6">
10383
<div class="flex items-center gap-2"><h1
10484
class="text-3xl font-bold bg-gradient-to-r from-indigo-600 to-purple-600 text-transparent bg-clip-text dark:from-indigo-400 dark:to-purple-400">
105-
GrammarPro</h1><span
106-
class="px-2 py-1 text-xs font-medium bg-indigo-100 text-indigo-800 rounded-full dark:bg-indigo-900 dark:text-indigo-200">Beta</span>
85+
AI Grammar Checker</h1>
10786
</div>
10887
<select id="mode-select"
10988
class="px-3 py-1 border rounded-md text-sm bg-white dark:bg-gray-700 text-gray-900 dark:text-gray-100 border-gray-300 dark:border-gray-600 focus:ring-2 focus:ring-indigo-500 dark:focus:ring-indigo-400 transition-colors duration-200">
@@ -159,6 +138,29 @@ <h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-cen
159138
Recent Corrections
160139
</h3>
161140
<div id="history-list" class="space-y-2"></div>
141+
<button id="show-all-errors" class="mt-4 px-4 py-2 bg-gray-600 hover:bg-gray-700 text-white rounded-md focus:outline-none focus:ring-2 focus:ring-gray-500 transition-colors duration-200 flex items-center gap-2 disabled:opacity-50 disabled:cursor-not-allowed">
142+
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
143+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M13 16h-1v-4h-1m1-4h.01M21 12a9 9 0 11-18 0 9 9 0 0118 0z"></path>
144+
</svg>
145+
Show All Errors
146+
</button>
147+
</div>
148+
<div id="error-modal" class="fixed inset-0 bg-black bg-opacity-50 hidden items-center justify-center z-50">
149+
<div class="bg-white dark:bg-gray-800 rounded-lg max-w-2xl w-full mx-4 max-h-[90vh] flex flex-col">
150+
<div class="p-4 border-b border-gray-200 dark:border-gray-700 flex justify-between items-center">
151+
<h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100">All Detected Errors</h3>
152+
<button id="close-modal" class="text-gray-500 hover:text-gray-700 dark:text-gray-400 dark:hover:text-gray-200">
153+
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24">
154+
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M6 18L18 6M6 6l12 12"></path>
155+
</svg>
156+
</button>
157+
</div>
158+
<div class="p-4 overflow-y-auto flex-1">
159+
<div id="error-list" class="space-y-4">
160+
<!-- Errors will be inserted here -->
161+
</div>
162+
</div>
163+
</div>
162164
</div>
163165
</div>
164166
<script>let errorHistory = [];
@@ -336,6 +338,85 @@ <h3 class="text-lg font-semibold text-gray-900 dark:text-gray-100 flex items-cen
336338
document.getElementById('input').value = savedText;
337339
updateWordCount();
338340
}
339-
});</script>
341+
});
342+
343+
// Initialize button state
344+
const showAllErrorsBtn = document.getElementById('show-all-errors');
345+
showAllErrorsBtn.disabled = true;
346+
347+
// Add modal functionality
348+
const errorModal = document.getElementById('error-modal');
349+
const closeModal = document.getElementById('close-modal');
350+
351+
showAllErrorsBtn.addEventListener('click', function() {
352+
showErrorModal();
353+
});
354+
355+
closeModal.addEventListener('click', function() {
356+
errorModal.classList.add('hidden');
357+
errorModal.classList.remove('flex');
358+
});
359+
360+
// Close modal when clicking outside
361+
errorModal.addEventListener('click', function(e) {
362+
if (e.target === errorModal) {
363+
errorModal.classList.add('hidden');
364+
errorModal.classList.remove('flex');
365+
}
366+
});
367+
368+
// Close modal with Escape key
369+
document.addEventListener('keydown', function(e) {
370+
if (e.key === 'Escape' && !errorModal.classList.contains('hidden')) {
371+
errorModal.classList.add('hidden');
372+
errorModal.classList.remove('flex');
373+
}
374+
});
375+
376+
function showErrorModal() {
377+
const errorList = document.getElementById('error-list');
378+
errorList.innerHTML = errors.map((error, index) => `
379+
<div class="p-4 bg-gray-50 dark:bg-gray-700 rounded-lg border border-gray-200 dark:border-gray-600">
380+
<div class="flex justify-between items-start">
381+
<div class="font-medium text-gray-900 dark:text-gray-100">Error ${index + 1}</div>
382+
<button onclick="applyCorrection('${error.text}', '${error.suggestion}')"
383+
class="text-sm px-3 py-1 bg-green-600 hover:bg-green-700 text-white rounded-md transition-colors duration-200">
384+
Apply Fix
385+
</button>
386+
</div>
387+
<div class="mt-2 space-y-2">
388+
<div class="text-sm">
389+
<span class="text-gray-500 dark:text-gray-400">Original text: </span>
390+
<span class="text-red-600 dark:text-red-400">${error.text}</span>
391+
</div>
392+
<div class="text-sm">
393+
<span class="text-gray-500 dark:text-gray-400">Suggestion: </span>
394+
<span class="text-green-600 dark:text-green-400">${error.suggestion}</span>
395+
</div>
396+
<div class="text-sm">
397+
<span class="text-gray-500 dark:text-gray-400">Description: </span>
398+
<span class="text-gray-900 dark:text-gray-100">${error.description}</span>
399+
</div>
400+
</div>
401+
</div>
402+
`).join('');
403+
404+
errorModal.classList.remove('hidden');
405+
errorModal.classList.add('flex');
406+
}
407+
408+
function applyCorrection(original, suggestion) {
409+
const input = document.getElementById('input');
410+
input.value = input.value.replace(original, suggestion);
411+
displayResults(input.value, errors.filter(e => e.text !== original));
412+
updateWordCount();
413+
showNotification(`Corrected: ${original}${suggestion}`, 'success');
414+
}
415+
416+
// Add this to your existing checkGrammar function, right after parsing the grammarData:
417+
window.errors = grammarData.errors; // Make errors globally available
418+
showAllErrorsBtn.disabled = grammarData.errors.length === 0;
419+
</script>
420+
<script src="../sidebar.js"></script>
340421
</body>
341422
</html>

0 commit comments

Comments
 (0)