User:Zocky/jsSandBox.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. |
![]() | This user script seems to have a documentation page at User:Zocky/jsSandBox and an accompanying .css page at User:Zocky/jsSandBox.css. |
//<pre><nowiki>
document.write('<script type="text/javascript" src="'
+ 'http://en.wikipedia.org/w/index.php?title=User:Zocky/Prototype.js'
+ '&action=raw&ctype=text/javascript&dontcountme=s\"><'+'/script>');
document.write('<link rel="stylesheet" type="text/css" href="'
+ 'http://test.wikipedia.org/w/index.php?title=User:Zocky/jsSandbox.css'
+ '&action=raw&ctype=text/css&dontcountme=s"/>');
var jsSandBoxAcActive=false;
var jsSandBoxAcMatches=[];
var jsSandBoxAcNext=0;
var jsSandBoxAcStart=0;
var jsSandBoxCode;
var jsSandBoxScroll;
addLoadEvent (jsSandBoxInit);
function jsSandBoxInit()
{
new Insertion.Top($('content'),'<div id="jsSandBox" style="display:none"><b>results</b> <a href="javascript:jsSandBoxClear()>(clear)</a></div>');
new Insertion.Bottom($('jsSandBox'),'<div id="jsSandBoxScroll"></div>');
new Insertion.Bottom($('jsSandBox'),'code <a href="javascript:jsSandBoxGo(jsSandBoxCode)">(eval)</a>');
new Insertion.Bottom($('jsSandBox'),'<textarea id="jsSandBoxCode" rows="6"></textarea>');
new Insertion.Bottom($('jsSandBox'),'<small>ctrl-enter to eval, ctr-space to autocomplete</small>');
jsSandBoxCode=$('jsSandBoxCode');
jsSandBoxScroll=$('jsSandBoxScroll');
Event.observe(jsSandBoxCode,'keyup',jsSandBoxKey,true);
new Insertion.Bottom($('t-specialpages').parentNode,'<li><a href="javascript:jsSandBoxToggle()">jsSandBox</a></li>');
if (wgNamespaceNumber==2 && wgPageName.match(/\.js$/) && $('wpTextbox1'))
{
Event.observe($('wpTextbox1'),'keyup',jsSandBoxKey,false);
}
}
function jsSandBoxToggle()
{
$('jsSandBox').style.display = $('jsSandBox').style.display=='none' ? 'block' : 'none';
}
function jsSandBoxClear()
{
jsSandBoxScroll.innerHTML='';
}
function jsSandBoxGo(target)
{
$('jsSandBox').style.display='block';
if (target.selectionStart!=target.selectionEnd)
{
code=target.value.substring(target.selectionStart,target.selectionEnd);
}
else
{
code=target.value;
}
var res = '<div class="jsSandBoxScrollCode" onclick="jsSandBoxRecall(this)">'
+ code
+ '</div>';
try
{
res += '<div class="jsSandBoxScrollResult">'
+ eval(code)
+ '</div>';
}
catch (err)
{
res += '<div class="jsSandBoxScrollError">'
+ '<b>' + err.name + '</b>: ' + err.message
+ '</div>';
}
new Insertion.Bottom(jsSandBoxScroll,
'<div class="jsSandBoxScrollItem">'
+ res
+ '</div>'
);
jsSandBoxScroll.scrollTop=1e12;
target.focus();
}
function jsSandBoxRecall(old)
{
jsSandBoxCode.value=old.innerHTML;
jsSandBoxCode.focus();
}
function jsSandBoxKey(e)
{
keynum = window.event ? e.keyCode : e.which ;
target=Event.element(e);
if (e.ctrlKey && keynum==13) { jsSandBoxGo(target);}
if (e.ctrlKey && keynum==32)
{
if (!jsSandBoxAcActive)
{
var find = target.value.substr(0,target.selectionStart).match(/\w[a-zA-Z0-9\.]*$/);
var where=find[0].split(/\./);
var thing = window;
try
{
for (var i=0;i<where.length-1;i++)
{
if (where[i]){thing=thing[where[i]]}
}
what=where[i];
var j=0;
jsSandBoxAcMatches=[];
for (var bit in thing)
{
if ( bit.substr(0,what.length) == what)
{
jsSandBoxAcMatches[j]=bit;
j++;
}
}
if (j>0)
{
jsSandBoxAcNext=0;
jsSandBoxAcStart=target.selectionStart-what.length;
jsSandBoxAcActive=true;
}
}
catch(e){return};
}
if(jsSandBoxAcActive)
{
var top=target.scrollTop;
target.value = target.value.substr(0,jsSandBoxAcStart)
+ jsSandBoxAcMatches[jsSandBoxAcNext]
+ target.value.substr(target.selectionStart);
target.selectionStart=jsSandBoxAcStart+jsSandBoxAcMatches[jsSandBoxAcNext].length;
target.selectionEnd=target.selectionStart;
jsSandBoxAcNext=(jsSandBoxAcNext+1) % jsSandBoxAcMatches.length;
target.scrollTop=top;
}
}
else jsSandBoxAcActive=false;
}