User:Lupin/evaluator.js
From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. In Internet Explorer and Firefox, hold down the Ctrl key and click the Refresh or Reload button. Opera users have to clear their caches through Tools→Preferences, see the instructions for Opera. Konqueror and Safari users can just click the Reload button.
//////////////////////////////////////////////////////////////// // 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){}; } addOnloadHook(addEvaluator); // // end evaluator ////////////////////////////////////////////////////////////////