Skip to content

Commit 8b04ee4

Browse files
Merge pull request #85 from angela479/grammarcheck
Added Grammar Check and SpellCheck using API
2 parents ff13a10 + 3d1bd9d commit 8b04ee4

File tree

3 files changed

+116
-13
lines changed

3 files changed

+116
-13
lines changed

index.html

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,22 @@ <h2>Resume Details</h2>
5454
<input type="url" id="input-github" placeholder="github.com/john" />
5555
<span class="error-message" id="error-github"></span>
5656
</div>
57+
5758
<div class="form-group">
58-
<label for="input-about">Professional Summary</label>
59-
<textarea id="input-about" placeholder="Passionate developer with 3 years of experience..."
60-
maxlength="300"></textarea>
61-
<span class="char-count" id="charCount-input-about"></span>
62-
<span class="error-message" id="error-about"></span>
63-
</div>
59+
<label for="input-about">Professional Summary</label>
60+
<textarea id="input-about" placeholder="Passionate developer with 3 years of experience..." maxlength="300"></textarea>
61+
<span class="char-count" id="charCount-input-about"></span>
62+
<span class="error-message" id="error-about"></span>
63+
64+
<!-- 💡 Grammar Improve Button -->
65+
<button type="button" class="improve-btn" onclick="improveText('input-about')">
66+
💡 GrammarCheck
67+
</button>
68+
69+
<!-- 🌟 Suggestion Output -->
70+
<div id="suggestion-input-about" class="suggestion-box"></div>
71+
</div>
72+
6473

6574
<!-- Education -->
6675
<div class="form-group fade-in">

script.js

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -507,3 +507,70 @@ function clearAndReload() {
507507
sessionStorage.clear();
508508
window.location.reload();
509509
}
510+
511+
async function improveText(textareaId) {
512+
const textarea = document.getElementById(textareaId);
513+
const suggestionBox = document.getElementById(`suggestion-${textareaId}`);
514+
let text = textarea.value;
515+
516+
// Show loading state
517+
suggestionBox.classList.add("loading");
518+
suggestionBox.style.display = "block";
519+
suggestionBox.innerText = "Checking for improvements...";
520+
521+
try {
522+
let improved = text;
523+
let hasMoreErrors = true;
524+
let safetyCounter = 0; // Avoid infinite loop
525+
526+
while (hasMoreErrors && safetyCounter < 5) {
527+
const response = await fetch("https://api.languagetool.org/v2/check", {
528+
method: "POST",
529+
headers: {
530+
"Content-Type": "application/x-www-form-urlencoded"
531+
},
532+
body: new URLSearchParams({
533+
text: improved,
534+
language: "en-US"
535+
})
536+
});
537+
538+
const data = await response.json();
539+
const matches = data.matches;
540+
541+
if (matches.length === 0) {
542+
hasMoreErrors = false;
543+
break;
544+
}
545+
546+
// Fix matches from last to first
547+
matches
548+
.sort((a, b) => b.offset - a.offset)
549+
.forEach(match => {
550+
if (match.replacements.length > 0) {
551+
const replacement = match.replacements[0].value;
552+
improved =
553+
improved.slice(0, match.offset) +
554+
replacement +
555+
improved.slice(match.offset + match.length);
556+
}
557+
});
558+
559+
safetyCounter++;
560+
}
561+
562+
suggestionBox.classList.remove("loading");
563+
564+
if (improved !== text) {
565+
suggestionBox.innerHTML = `✨ <strong>Suggested:</strong> "${improved}"`;
566+
} else {
567+
suggestionBox.innerText = "✅ Your text looks good!";
568+
}
569+
570+
} catch (error) {
571+
suggestionBox.classList.remove("loading");
572+
suggestionBox.innerText = "❌ Error checking grammar.";
573+
console.error(error);
574+
}
575+
}
576+

style.css

Lines changed: 34 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -307,24 +307,51 @@ main {
307307
/* Responsive Footer */
308308

309309
.footer {
310-
background-color: #f1f1f1; /* light mode background */
311-
color: #333;
310+
background-color: #f1f1f1;
312311
}
313312

314313
.footer-link {
315-
color: #333;
314+
color: #b21d1d;
316315
text-decoration: none;
317316
}
318317

319318
body.dark .footer {
320-
background-color: #1a1a1a; /* darker shade for footer in dark mode */
319+
background-color: #1a1a1a;
321320
color: #eee;
322-
border-top: 1px solid #444; /* subtle top border */
323-
box-shadow: 0 -2px 5px rgba(255, 255, 255, 0.05); /* soft top glow effect */
321+
border-top: 1px solid #444;
322+
box-shadow: 0 -2px 5px rgba(255, 255, 255, 0.05);
324323
}
325324

326325
body.dark .footer-link {
327-
color: #ffcc00; /* dark yellow for better contrast */
326+
color: #ffcc00;
327+
}
328+
329+
.improve-btn {
330+
margin-top: 8px;
331+
background: none;
332+
border: none;
333+
color: #007BFF;
334+
cursor: pointer;
335+
font-size: 14px;
336+
text-decoration: underline;
337+
display: inline-block;
338+
}
339+
340+
.suggestion-box {
341+
margin-top: 10px;
342+
font-size: 14px;
343+
color: green;
344+
background: #e9fbe9;
345+
padding: 10px;
346+
border-left: 4px solid green;
347+
border-radius: 4px;
348+
display: none;
349+
}
350+
351+
.suggestion-box.loading {
352+
color: gray;
353+
font-style: italic;
354+
display: block;
328355
}
329356

330357

0 commit comments

Comments
 (0)