Jump to content

User:Zocky/wc.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
function $(id){return document.getElementById(id)}

$(wcInit);

function wcInit()
{
  code = '<textarea id="wcText" style="width:100%;height:400px"></textarea>'
       + '<div id="wcResult" style="height:7em;background:#def"></div>'
       + '<input type="button" value="go" onclick="wcGo()"><p>';
  $('content').innerHTML=code+$('content').innerHTML;
}
function wcGo()
{
  text = $('wcText').value;
  result=text.length+" characters<br>";

  result+=(n = text.replace(/\s+/g,'').length) + " non-space characters<br>";
  result+=text.split(/\s+/).length + " words<br>";
  result+=Math.ceil(n/750)/2 + " standard pages<br>";
  $('wcResult').innerHTML=result;
}