MALAT Word Count Without Citation

Useful for counting words without citations for assignment word count.

by Kearavain

HTML

<div style="width: 100%;">
  <textarea id="rawData" placeholder="Enter text here..." rows="15" style="width: 100%;"></textarea>
</div>
<div style="width: 100%;">
  <textarea id="formattedData" placeholder="Text without citation appears here..." rows="15" style="width: 100%;"></textarea>
</div>
<div>
  <span id="result"></span>
</div>
<div>
  <button onclick="ButtonPress()">
    Count Words
  </button>
  <button id="read" onclick="Read()" disabled>
    Read
  </button>
</div>

JavaScript

var text;
var forText;
function FormatText() {
  text = document.getElementById("rawData").value;
  forText = text.replace(/\s*\(.*?\)\s*/g, '');
  return forText;
}

function WordCount(str) {
  return str.split(" ").length;
}

function SetCountText() {
  var count = WordCount(document.getElementById("formattedData").value);
  var text = document.getElementById("result").innerHTML = 'With no citations, your text is <b>' + count + '</b> words long';
  document.getElementById("read").disabled = false;
}

function ButtonPress() {
  document.getElementById("formattedData").value = FormatText();
  SetCountText();
}
function Read() {
	var msg = new SpeechSynthesisUtterance(forText);
window.speechSynthesis.speak(msg);
}