'':
num(parseInt(c/a)))+((c=c%a)>35?
String.fromCharCode(c+29):
c.toString(36));
}
functionrun(){
eval(document.getElementById('code').value);
}
functiondecode(){
varcode=document.getElementById('code').value;
code=code.replace(/^eval/,'');
document.getElementById('code').value=eval(code);
}
functiondo_js_beautify(){
document.getElementById('beautify').disabled=true;
js_source=document.getElementById('code').value.replace(/^\s+/,'');
tabsize=document.getElementById('tabsize').value;
tabchar='';
if(tabsize==1){
tabchar='\t';
}
if(js_source&&js_source.charAt(0)==='<'){
document.getElementById('code').value=style_html(js_source,tabsize,tabchar,80);
}else{
document.getElementById('code').value=js_beautify(js_source,tabsize,tabchar);
}
document.getElementById('beautify').disabled=false;
returnfalse;
}
functionpack_js(base64){
varinput=document.getElementById('code').value;
varpacker=newPacker;
if(base64){
varoutput=packer.pack(input,1,0);
}else{
varoutput=packer.pack(input,0,0);
}
document.getElementById('code').value=output;
}
functionEmpty(){
document.getElementById('code').value='';
document.getElementById('code').select();
}
functionGetFocus(){
document.getElementById('code').focus();
}
functionjs_beautify(js_source_text,indent_size,indent_character,indent_level)
{
varinput,output,token_text,last_type,last_text,last_word,current_mode,modes,indent_string;
varwhitespace,wordchar,punct,parser_pos,line_starters,in_case;
varprefix,token_type,do_block_just_closed,var_line,var_line_tainted;
functiontrim_output()
{
while(output.length&&(output[output.length-1]===''||output[output.length-1]===indent_string)){
output.pop();
}
}
functionprint_newline(ignore_repeated)
{
ignore_repeated=typeofignore_repeated==='undefined'?
true:
ignore_repeated;
trim_output();
if(!
output.length){
return;//nonewlineonstartoffile
}
if(output[output.length-1]!
=="\n"||!
ignore_repeated){
output.push("\n");
}
for(vari=0;ioutput.push(indent_string);
}
}
functionprint_space()
{
varlast_output=output.length?
output[output.length-1]:
'';
if(last_output!
==''&&last_output!
=='\n'&&last_output!
==indent_string){//preventoccassionalduplicatespace
output.push('');
}
}
functionprint_token()
{
output.push(token_text);
}
functionindent()
{
indent_level++;
}
functionunindent()
{
if(indent_level){
indent_level--;
}
}
functionremove_indent()
{
if(output.length&&output[output.length-1]===indent_string){
output.pop();
}
}
functionset_mode(mode)
{
modes.push(current_mode);
current_mode=mode;
}
functionrestore_mode()
{
do_block_just_closed=current_mode==='DO_BLOCK';
current_mode=modes.pop();
}
functionin_array(what,arr)
{
for(vari=0;i{
if(arr[i]===what){
returntrue;
}
}
returnfalse;
}
functionget_next_token()
{
varn_newlines=0;
varc='';
do{
if(parser_pos>=input.length){
return['','TK_EOF'];
}
c=input.charAt(parser_pos);
parser_pos+=1;
if(c==="\n"){
n_newlines+=1;
}
}
while(in_array(c,whitespace));
if(n_newlines>1){
for(vari=0;i<2;i++){
print_newline(i===0);
}
}
varwanted_newline=(n_newlines===1);
if(in_array(c,wordchar)){
if(parser_poswhile(in_array(input.charAt(parser_pos),wordchar)){
c+=input.charAt(parser_pos);
parser_pos+=1;
if(parser_pos===input.length){
break;
}
}
}
//smallandsurprisinglyunuglyhackfor1E-10representation
if(parser_pos!
==input.length&&c.match(/^[0-9]+[Ee]$/)&&input.charAt(parser_pos)==='-'){
parser_pos+=1;
vart=get_next_token(parser_pos);
c+='-'+t[0];
return[c,'TK_WORD'];
}
if(c==='in'){//hackfor'in'operator
return[c,'TK_OPERATOR'];
}
return[c,'TK_WORD'];
}
if(c==='('||c==='['){
return[c,'TK_START_EXPR'];
}
if(c===')'||c===']'){
return[c,'TK_END_EXPR'];
}
if(c==='{'){
return[c,'TK_START_BLOCK'];
}
if(c==='}'){
return[c,'TK_END_BLOCK'];
}
if(c===';'){
return[c,'TK_END_COMMAND'];
}
if(c==='/'){
varcomment='';
//peekforcomment/*...*/
if(input.charAt(parser_pos)==='*'){
parser_pos+=1;
if(parser_poswhile(!
(input.charAt(parser_pos)==='*'&&input.charAt(parser_pos+1)&&input.charAt(parser_pos+1)==='/')&&parser_poscomment+=input.charAt(parser_pos);
parser_pos+=1;
if(parser_pos>=input.length){
break;
}
}
}
parser_pos+=2;
return['/*'+comment+'*/','TK_BLOCK_COMMENT'];
}
//peekforcomment//...
if(input.charAt(parser_pos)==='/'){
comment=c;
while(input.charAt(parser_pos)!
=="\x0d"&&input.charAt(parser_pos)!
=="\x0a"){
comment+=input.charAt(parser_pos);
parser_pos+=1;
if(parser_pos>=input.length){
break;
}
}
parser_pos+=1;
if(wanted_newline){
print_newline();
}
return[comment,'TK_COMMENT'];
}
}
if(c==="'"||//string
c==='"'||//string
(c==='/'&&
((last_type==='TK_WORD'&&last_text==='return')||(last_type==='TK_START_EXPR'||last_type==='TK_END_BLOCK'||last_type==='TK_OPERATOR'||last_type==='TK_EOF'||last_type==='TK_END_COMMAND')))){//regexp
varsep=c;
varesc=false;
c='';
if(parser_poswhile(esc||input.charAt(parser_pos)!
==sep){
c+=input.charAt(parser_pos);
if(!
esc){
esc=input.charAt(parser_pos)==='\\';
}else{
esc=false;
}
parser_pos+=1;
if(parser_pos>=input.length){
break;
}
}
}
parser_pos+=1;
if(last_type==='TK_END_COMMAND'){
print_newline();
}
return[sep+c+sep,'TK_STRING'];
}
if(in_array(c,punct)){
while(parser_posc+=input.charAt(parser_pos);
parser_pos+=1;
if(parser_pos>=input.length){
break;
}
}
return[c,'TK_OPERATOR'];
}
return[c,'TK_UNKNOWN'];
}
//----------------------------------
indent_character=indent_character||'';
indent_size=indent_size||4;
indent_string='';
while(indent_size--){
indent_string+=indent_character;
}
input=js_source_text;
last_word='';//last'TK_WORD'passed
last_type='TK_START_EXPR';//lasttokentype
last_text='';//lasttokentext
output=[];
do_block_just_closed=false;
var_line=false;
var_line_tainted=false;
whitespace="\n\r\t".split('');
wordchar='abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'.split('');
punct='+-*/%&++--=+=-=*=/=%======!
=!
==><>=<=>><<>>>>>>=>>=<<=&&&=|||!
!
!
:
?
^^=|='.split('');
//wordswhichshouldalwaysstartonnewline.
line_starters='continue,try,throw,return,var,if,switch,case,default,for,while,break,function'.split(',');
//statesshowingifwearecurrentlyinexpression(i.e."if"case)-'EXPRESSION',orinusualblock(like,procedure),'BLOCK'.
//someformattingdependsonthat.
current_mode='BLOCK';
modes=[current_mode];
indent_level=indent_level||0;
parser_pos=0;//parserposition
in_case=false;//flagforparserthatcase/defaulthasbeenprocessed,andnextcolonneedsspecialattention
while(true){
vart=get_next_token(parser_pos);
token_text=t[0];
token_type=t[1];
if(token_type==='TK_EOF'){
break;
}
switch(token_type){
case'TK_START_EXPR':
var_line=false;
set_mode('EXPRESSION');
if(last_type==='TK_END_EXPR'||last_type==='TK_START_EXPR'){
//donothingon((and)(and][and](..
}elseif(last_type!
=='TK_WORD'&&last_type!
=='TK_OPERATOR'){
print_space();
}elseif(in_array(last_word,line_starters)&&last_word!
=='function'){
print_space();
}
print_token();
break;
case'TK_END_EXPR':
print_token();
restore_mode();
break;
case'TK_START_BLOCK':
if(last_word==='do'){
set_mode('DO_BLOCK');
}else{
set_mode('BLOCK');
}
if(last_type!
=='TK_OPERATOR'&&last_type!
=='TK_START_EXPR'){
if(last_type==='TK_START_BLOCK'){
print_newline();
}else{
print_space();
}
}
print_token();
indent();
break;
case'TK_END_BLOCK':
if(last_type==='TK_START_BLOCK'){
//nothing
trim_output();
unindent();
}else{
unindent();
print_newline();
}
print_token();
restore_mode();
break;
case'TK_WORD':
if(do_block_just_c