Jump to content

User:Lupin/evaluator.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.
////////////////////////////////////////////////////////////////
// Evaluator
// Source: http://krolik.net/js-eval.shtml

var evaluatorHTML='<FORM ID="Tester" NAME="Tester" onsubmit="return TesterExecute();" >' +
  '<TEXTAREA NAME="MyCommand" COLS=60 ROWS=25 WRAP="off"></TEXTAREA>' +
  '<TEXTAREA NAME="MyResult" COLS=40 ROWS=25 WRAP="off"></TEXTAREA>' + 
  '<BR>' + 
  '<INPUT TYPE=BUTTON value="Show Object" onclick="ObjectDumpClicked();" >' + 
  '<INPUT TYPE=BUTTON value="Execute" onclick="TesterExecute();">' + 
  '</FORM>';

function ObjectDump(strObject) 
{
  var strOutput; 
  var vTemp; 
  var vAnotherTemp; 
  var vElement;
  vElement = eval(strObject); 
  strOutput = "typeof = " + typeof(vElement) + "\n\n";
  AppendOutput(strOutput);
  for (var x in vElement )  
  { 
   vTemp = strObject + "." + x.toString() ; 
   vAnotherTemp = strObject + "[" + x + "]" ; 
   strOutput = strOutput + vTemp + " = " + eval(vTemp) + "\n";
   AppendOutput(vTemp + " = " + eval(vTemp) + "\n");
  } 
  return strOutput ;  
 } 
 function AppendOutput(strText)
 {
  document.Tester.MyResult.value = document.Tester.MyResult.value + strText;
 }
 function Output(strText)
 {
  document.Tester.MyResult.value = strText;
 }
 function ObjectDumpClicked() 
 {
  document.Tester.MyResult.value="";
  ObjectDump(document.Tester.MyCommand.value); 
  return false;
 }
 function TesterExecute() 
 {       
  document.Tester.MyResult.value="";
  document.Tester.MyResult.value=eval(document.Tester.MyCommand.value); 
  return false;
 }

function addEvaluator() {
  try { 
    var evalNode=document.createElement('div');
    evalNode.id='evalNode';
    evalNode.innerHTML=evaluatorHTML;
    document.body.appendChild(evalNode);
    document.Tester=document.getElementById('Tester'); 
  }
  catch(err){};
}

$(addEvaluator);

//
// end evaluator
////////////////////////////////////////////////////////////////