โ“ Help Closed

Ruyi

๐™ณ๐šž๐š”๐šŽ ๐š˜๐š ๐™ฟ๐™ท๐™ฒ
Elite
.
 
JavaScript:
// Get the text area and count elements
var textInput = document.getElementById('text-input');
var wordCountElement = document.getElementById('word-count');
var sentenceCountElement = document.getElementById('sentence-count');

// Add an event listener to the text area
textInput.addEventListener('input', function() {
  // Get the text from the text area
  var text = textInput.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
  wordCountElement.textContent = 'Word Count: ' + wordCount;
  sentenceCountElement.textContent = 'Sentence Count: ' + sentenceCount;
});

// Add an event listener to the start-ocr button
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
        textInput.value = text;
        // Trigger the input event to update counts
        textInput.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.');
      });
    });
  }
});
 
JavaScript:
// Get the text area and count elements
var textInput = document.getElementById('text-input');
var wordCountElement = document.getElementById('word-count');
var sentenceCountElement = document.getElementById('sentence-count');

// Add an event listener to the text area
textInput.addEventListener('input', function() {
  // Get the text from the text area
  var text = textInput.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
  wordCountElement.textContent = 'Word Count: ' + wordCount;
  sentenceCountElement.textContent = 'Sentence Count: ' + sentenceCount;
});

// Add an event listener to the start-ocr button
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
        textInput.value = text;
        // Trigger the input event to update counts
        textInput.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.');
      });
    });
  }
});
Ganon parin siya lods pero wala namang error sa console

Yung isang code naman ang hindi nag work
 

Similar threads

About this Thread

  • 2
    Replies
  • 486
    Views
  • 2
    Participants
Last reply from:
Ruyi

Online now

Members online
1,014
Guests online
1,333
Total visitors
2,347

Forum statistics

Threads
2,276,213
Posts
28,968,356
Members
1,231,168
Latest member
nrking
Back
Top