34 lines
936 B
JavaScript
34 lines
936 B
JavaScript
window.onload = () => {
|
|
const btnCheck = document.getElementById('btn-check')
|
|
btnCheck.addEventListener('click', checkText)
|
|
}
|
|
|
|
function checkText() {
|
|
const textArea = document.getElementById('besana-editor')
|
|
const textAreaValue = textArea?.textContent
|
|
console.log(textAreaValue)
|
|
const paragraphs = separateParagraphs(textAreaValue)
|
|
console.log(paragraphs)
|
|
const modifiedParagraphs = paragraphs.map(paragraph =>
|
|
mockSpellChecker(paragraph)
|
|
)
|
|
console.log(modifiedParagraphs)
|
|
textArea.innerHTML = modifiedParagraphs.join('\n')
|
|
}
|
|
|
|
function separateParagraphs(text) {
|
|
return text.split('\n')
|
|
}
|
|
|
|
function mockSpellChecker(text) {
|
|
const words = text.split(' ')
|
|
const specificWords = ['Tole', 'nov', 'dolor']
|
|
const modifiedWords = words.map(word => {
|
|
if (specificWords.includes(word)) {
|
|
return `<span class="typo-mistake">${word}</span>`
|
|
}
|
|
return word
|
|
})
|
|
return modifiedWords.join(' ')
|
|
}
|