-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
"Added spellcheck attribute to textarea, error list display, and lang…
…uageTool.js script inclusion"
- Loading branch information
Showing
2 changed files
with
42 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
async function checkGrammar(text, language) { | ||
const response = await fetch('https://api.languagetool.org/v2/check', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/x-www-form-urlencoded', | ||
}, | ||
body: new URLSearchParams({ | ||
'text': text, | ||
'language': language, // 'ar' for Arabic, 'en' for English | ||
}) | ||
}); | ||
|
||
const data = await response.json(); | ||
displayGrammarErrors(data.matches); | ||
} | ||
|
||
function displayGrammarErrors(matches) { | ||
const errorList = document.getElementById('errorList'); | ||
errorList.innerHTML = ''; // Clear previous errors | ||
|
||
matches.forEach(match => { | ||
const errorItem = document.createElement('li'); | ||
errorItem.textContent = `${match.message} - اقتراح: ${match.replacements.map(rep => rep.value).join(', ')}`; | ||
errorList.appendChild(errorItem); | ||
}); | ||
} | ||
|
||
let typingTimer; | ||
const doneTypingInterval = 2000; | ||
|
||
document.getElementById('essayInput').addEventListener('input', function() { | ||
clearTimeout(typingTimer); | ||
typingTimer = setTimeout(() => { | ||
const text = document.getElementById('essayInput').value; | ||
const language = /[\u0600-\u06FF]/.test(text) ? 'ar' : 'en'; // Detect Arabic characters | ||
checkGrammar(text, language); | ||
}, doneTypingInterval); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters