User:Lupin/evaluator.js
Appearance
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump. This code will be executed when previewing this page. |
Documentation for this user script can be added at User:Lupin/evaluator. |
////////////////////////////////////////////////////////////////
// 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
////////////////////////////////////////////////////////////////