// Get the text area and count elements
var textInput1 = document.getElementById('text-input1');
var wordCountElement1 = document.getElementById('word-count1');
var sentenceCountElement1 = document.getElementById('sentence-count1');
// Add an event listener to the text area
textInput1.addEventListener('input', function() {
// Get the text from the text area
var text = textInput1.value;
// Count the words by splitting the text on any whitespace character and filtering out empty strings
var words = text.split(/\s+/).filter(function(word) {
return word !== '';
});
var wordCount = words.length;
// Count the sentences by splitting the text on periods, exclamation marks, and question marks
var sentences = text.split(/[.!?]/).filter(function(sentence) {
return sentence !== '';
});
var sentenceCount = sentences.length;
// Update the word and sentence count elements
wordCountElement1.textContent = 'Word Count: ' + wordCount;
sentenceCountElement1.textContent = 'Sentence Count: ' + sentenceCount;
});
// Add below your existing event listener
document.getElementById('start-ocr').addEventListener('click', function() {
var fileSelector = document.getElementById('file-selector');
if (fileSelector.files.length > 0) {
var file = fileSelector.files[0];
Tesseract.createWorker().then(worker => {
worker.recognize(file).then(function(result) {
// Get the recognized text from the result
var text = result.data.text;
// Set the recognized text as input
textInput1.value = text;
// Trigger the input event to update counts
textInput1.dispatchEvent(new Event('input'));
// Terminate the worker
worker.terminate();
}).catch(function(error) {
// Handle any errors that might occur
console.error(error);
alert('An error occurred while performing OCR.');
});
})
}
});
// Get the text area and count elements
var textInput2 = document.getElementById('text-input2');
var wordCountElement2 = document.getElementById('word-count2');
var sentenceCountElement2 = document.getElementById('sentence-count2');
// Add an event listener to the text area
textInput2.addEventListener('input', function() {
// Get the text from the text area
var text = textInput2.value;
// Count the words by splitting the text on any whitespace character and filtering out empty strings
var words = text.split(/\s+/).filter(function(word) {
return word !== '';
});
var wordCount = words.length;
// Count the sentences by splitting the text on periods, exclamation marks, and question marks
var sentences = text.split(/[.!?]/).filter(function(sentence) {
return sentence !== '';
});
var sentenceCount = sentences.length;
// Update the word and sentence count elements
wordCountElement2.textContent = 'Word Count: ' + wordCount;
sentenceCountElement2.textContent = 'Sentence Count: ' + sentenceCount;
});
// Add below your existing event listener
document.getElementById('start-ocr').addEventListener('click', function() {
var fileSelector = document.getElementById('file-selector');
if (fileSelector.files.length > 0) {
var file = fileSelector.files[0];
Tesseract.createWorker().then(worker => {
worker.recognize(file).then(function(result) {
// Get the recognized text from the result
var text = result.data.text;
// Set the recognized text as input
textInput2.value = text;
// Trigger the input event to update counts
textInput2.dispatchEvent(new Event('input'));
// Terminate the worker
worker.terminate();
}).catch(function(error) {
// Handle any errors that might occur
console.error(error);
alert('An error occurred while performing OCR.');
});
})
}
});