欢迎来到福编程网,本站提供各种互联网专业知识!

JS代码格式化和语法着色V2

发布时间:2006-10-14 作者: 来源:转载
升级到第二版,开一贴以示庆贺,哈哈哈自Ver1.1升级内容1.增加函数列表2.增加函数Export功能3.增加函数依存关系分析(这个功能个人未见其他软件实现过,自己创意,问题多多,目前分析能力还是比较有限的,只能分析全局函数依存关系,可能在复杂代码的情况下出
升级到第二版,开一贴以示庆贺,哈哈哈

自Ver1.1升级内容
1.增加函数列表
2.增加函数Export功能
3.增加函数依存关系分析(这个功能个人未见其他软件实现过,自己创意,问题多多,目前分析能力还是比较有限的,只能分析全局函数依存关系,可能在复杂代码的情况下出现bug)
4.修正for语句分析bug
5.修正语法折叠的bug
6.改进CollapseAll※ExpandAll函数工作方式,避免行数太大时的死机
7.改进行号分析机制,避免行数太大时的死机
复制代码 代码如下:


JSerVer2.0



/**********************
Author:Hutia

*********************/

window.onload=init;


//------------------
//StaticVariable
//------------------

varKEYWORDS="abstractbreakbytecasecatchcharclassconstcontinuedefaultdeletedodoubleelseextendsfalsefinal
finallyfloatforfunctiongotoifimplementsimportininstanceofintinterfacelongnativenullpackageprivateprotected
publicresetreturnshortstaticsuperswitchsynchronizedthisthrowtransienttruetryvarvoidwhilewith";
varOBJECTS="AnchorAppletAreaArgumentsArrayBooleanButtonCheckboxCollectionCryptoDateDictionaryDocumentDrive
DrivesElementEnumeratorEventFileFileObjectFileSystemObjectFileUploadFolderFoldersFormFrameFunctionGlobalHidden
HistoryHTMLElementImageInfinityInputJavaArrayJavaClassJavaObjectJavaPackageJSObjectLayerLinkMathMimeType
NavigatorNumberObjectOptionPackagesPasswordPluginPrivilegeManagerRandomRegExpScreenSelectStringSubmitText
TextareaURLVBArrayWindowWScript";
varMETHODS_PROPERTIES="aboveabsacosactionactiveElementalertalinkColorallaltKeyanchoranchorsappCodeNameapplets
applyappNameappVersionargumentsarityasinassignatanatan2atobavailHeightavailLeftavailTopavailWidthActiveXObject
backbackgroundbelowbgColorbigblinkblurboldborderborderWidthsbottombtoabuttoncallcalleecallercancelBubble
captureEventsceilcharAtcharCodeAtcharsetcheckedchildrenclassesclassNameclearclearIntervalclearTimeoutclick
clientInformationclientXclientYcloseclosedcolorDepthcompilecompleteconcatconfirmconstructircontainscontextual
cookiecoscryptoctrlKeycurrentdatadefaultCharsetdefaultCheckeddefaultSelecteddefaultStatusdefaultValuedescription
disableExternalCapturedisablePrivilegedocumentdomainEEchoelementelementsembedsenabledPluginenableExternalCapture
enablePrivilegeencodingescapeevaleventexecexpexpandoFromPointfgColorfileNamefindfixedfloorfocusfontColor
fontSizeformformsforwardframesfromCharCodefromElementgetAttributegetgetClassgetDategetDaygetFullYeargetHours
getMembergetMillisecondsgetMinutesgetMonthgetSecondsgetSelectiongetSlotgetTimegetTimezoneOffsetgetUTCDategetUTCDay
getUTCFullYeargetUTCHoursgetUTCMillisecondsgetUTCMinutesgetUTCMonthgetUTCSecondsgetWindowgetYearglobalgoHandleEvent
HeighthashhiddenhistoryhomehosthostNamehrefhspaceididsignoreCaseimagesindexindexOfinnerinnerHTMLinnerText
innerWidthinsertAdjacentHTMLinsertAdjacentTextisFiniteisNANitalicsjavajavaEnabledjoinkeyCodeLinksLN10LN2LOG10E
LOG2ElanglanguagelastIndexlastIndexOflastMatchlastModifiedlastParenlayerslayerXlayerYleftleftContextlengthlink
linkColorloadlocationlocationBarloglowsrcMAX_VALUEMIN_VALUEmarginsmatchmaxmenubarmethodmimeTypesminmodifiers
moveAbovemoveBelowmoveBymoveTomoveToAbsolutemultilineNaNNEGATIVE_INFINITYnamenavigatenavigatornetscapenext
numberoffscreenBufferingoffsetoffsetHeightoffsetLeftoffsetParentoffsetTopoffsetWidthoffsetXoffsetYonabortonblur
onchangeonclickondblclickondragdroponerroronfocusonHelponkeydownonkeypressonkeyuponloadonmousedownonmousemove
onmouseoutonmouseoveronmouseuponmoveonresetonresizeonsubmitonunloadopenopeneroptionsouterHeightouterHTML
outerTextouterWidthPOSITIVE_INFINITYPIpaddingspageXpageXOffsetpageYpageYOffsetparentparentElementparentLayer
parentWindowparseparseFloatparseIntpathnamepersonalbarpixelDepthplatformpluginspopportpowpreferenceprevious
printpromptprotocolprototypepushrandomreadyStatereasonreferrerrefreshreleaseEventsreloadremoveAttribute
removeMemberreplaceresizeByresizeToreturnValuereverserightrightcontextroundSQRT1_2SQRT2screenXscreenYscroll
scrollbarsscrollByscrollIntoViewscrollTosearchselectselectedselectedIndexselfsetAttributesetDaysetFullYear
setHotkeyssetHourssetIntervalsetMembersetMillisecondssetMinutessetMonthsetResizablesetSecondssetSlotsetTime
setTimeoutsetUTCDatesetUTCFullYearsetUTCHourssetUTCMillsecondssetUTCMinutessetUTCMonthsetUTCSecondssetYear
setZOptionsshiftshiftKeysiblingAbovesiblingBelowsignTextsinslicesmallsortsourcesourceIndexsplicesplitsqrtsrc
srcElementsrcFilterstatusstatusbarstopstrikestylesubsubmitsubstrsubstringsuffixessunsupsystemLanguageTYPE
tagNametagstainttaintEnabledtantargettesttexttitletoElementtoGMTStringtoLocaleStringtoLowerCasetoolbartop
toStringtoUpperCasetoUTCStringtypetypeOfUTCunescapeunshiftuntaintunwatchuserAgentuserLanguagevaluevalueOf
visibilityvlinkColorvspacewatchwhichwidthwindowwritewritelnxyzIndex";
varOPS="!$%&*+-///:<=>?[]^|~isnewsizeoftypeofunchecked";

varregKW=newRegExp("(W"+KEYWORDS.replace(//g,"$)|(W")+"$)","g");
varregObj=newRegExp("(W"+OBJECTS.replace(//g,"$)|(W")+"$)","g");
varregMP=newRegExp("(W"+METHODS_PROPERTIES.replace(//g,"$)|(W")+"$)","g");
//varregOP=newRegExp("(W"+OPS.replace(//g,"$)|(W")+"$)","g");

//------------------
//GlobalVariables
//------------------
vardivJSInput,txtJSInput,divMain,divJSOutputLineNo,divJSOutputPlus,divJSOutput,divWaiting;
varspnProcess,cmdStop,divJSExport,selJSExport,divJSExportContent;
varglbStr,glbP,glbRe,curRe,glbTimer,glbBusy,glbFuntionNames;


functioninit(){
//initglobalvariables
divJSInput=document.getElementById("divJSInput");
txtJSInput=document.getElementById("txtJSInput");
divMain=document.getElementById("divMain");
divJSOutputLineNo=document.getElementById("divJSOutputLineNo");
divJSOutputPlus=document.getElementById("divJSOutputPlus");
divJSOutput=document.getElementById("divJSOutput");
divWaiting=document.getElementById("divWaiting");
spnProcess=document.getElementById("spnProcess");
cmdStop=document.getElementById("cmdStop");
divJSExport=document.getElementById("divJSExport");
selJSExport=document.getElementById("selJSExport");
divJSExportContent=document.getElementById("divJSExportContent");

//initwindowstate
maximizeWindow();

divMain.style.width=document.body.clientWidth-4;
divMain.style.height=document.body.clientHeight-26;

divJSOutput.style.width=document.body.clientWidth-72;


//initglobalevents

divJSOutputLineNo.onselectstart=divJSOutputLineNo.onselect=divJSOutputPlus.onselectstart=divJSOutputPlus.onselect=cancelEvent

divJSOutput.onscroll=divJSOutput_onscroll;

divJSInput.onkeydown=divJSInput_keydown;
divJSExport.onkeydown=divJSExport_keydown;

}


//------------------
//eventscripts
//------------------

functioncancelEvents(e){
vare=window.event?window.event:e;
e.returnValue=false;
return(false);
}

functiondivJSInput_keydown(e){
vare=window.event?window.event:e;
varsrcEle=e.srcElement?e.srcElement:e.target;
varsel;
if(e.keyCode==27)hideJSInput();
if(e.keyCode==13&&e.ctrlKey)execJSInput();
if(e.keyCode==9&&srcEle==txtJSInput){
document.selection.createRange().text="t";return(false);//notsupportFF
}
}

functiondivJSExport_keydown(e){
vare=window.event?window.event:e;
varsrcEle=e.srcElement?e.srcElement:e.target;
varsel;
if(e.keyCode==27)hideJSExport();
if(e.keyCode==13&&e.ctrlKey)hideJSExport();
}

functiondivJSOutput_onscroll(){
divJSOutputLineNo.scrollTop=divJSOutputPlus.scrollTop=divJSOutput.scrollTop;
}

//------------------
//functionalscripts
//------------------

functionshowJSInput(){
if(glbBusy)return;
hideJSExport();
with(divJSInput.style){
display="block";
left=(document.body.clientWidth-divJSInput.offsetWidth)/2;
top=(document.body.clientHeight-divJSInput.offsetHeight)/2;
}

txtJSInput.focus();

return(false);
}

functionshowJSExport(){
if(glbBusy)return;
hideJSInput();
with(divJSExport.style){
display="block";
left=(document.body.clientWidth-divJSExport.offsetWidth)/2;
top=(document.body.clientHeight-divJSExport.offsetHeight)/2;
}
divJSExportContent.style.display="none";
selJSExport.style.display="block";

selJSExport.focus();
return(false);
}

functionhideJSInput(){
divJSInput.style.display="none";
}

functionhideJSExport(){
divJSExport.style.display="none";
}

functionexecJSInput(){
hideJSInput();

divJSOutput.innerHTML="";
divJSOutputLineNo.innerHTML="";
divJSOutputPlus.innerHTML="";

glbStr=txtJSInput.innerText;//notsupportFF
glbP=0;
glbFuntionNames=newArray();
curRe=glbRe=document.createElement("div");

divJSOutput.appendChild(glbRe);
glbRe.className="codeRoot";

while(selJSExport.options.length>0)selJSExport.options[0]=null;

showWait(startRecalcLine);
core_analysis();
}

functionexecJSExport(){
varfns=newArray(),fcs=newArray(),str;

for(vari=0;iif(selJSExport.options[i].selected){
fns.push(selJSExport.options[i].value);
str=selJSExport.options[i].obj.outerHTML;
try{
str+=selJSExport.options[i].obj.nextSibling.outerHTML;
str+=selJSExport.options[i].obj.nextSibling.nextSibling.outerHTML;
}catch(e){}
fcs.push(str);
}
}
if(fns.length==0)return;

divJSExportContent.style.display="block";
selJSExport.style.display="none";

divJSExportContent.innerHTML=fcs.join("rn

rn");
}

functionexecJSExport_Dep(){
varfns=newArray(),fcs=newArray(),str,regFNs=newArray(),needDepthTest;

for(vari=0;iif(selJSExport.options[i].selected){
fns.push(selJSExport.options[i].value);
try{
str=selJSExport.options[i].obj.nextSibling.outerHTML;
}catch(e){}
fcs.push(str);
}
}
if(fns.length==0)return;

divJSExportContent.style.display="none";
selJSExport.style.display="block";

needDepthTest=false;
for(vari=0;iif(!selJSExport.options[i].selected){
for(j=0;jif(html2txt(fcs[j]).match(glbFuntionNames[i].replace(/./g,"."))){
selJSExport.options[i].selected=true;
needDepthTest=true;
break;
}
}
}
}
if(needDepthTest)execJSExport_Dep();
}


functionshowWait(onstop){
glbBusy=true;
document.body.style.cursor="wait";

with(divWaiting.style){
display="block";
left=(document.body.clientWidth-divWaiting.offsetWidth)/2;
top=(document.body.clientHeight-divWaiting.offsetHeight)/2;
}
spnProcess.innerHTML="0.00%(0/0)";
divWaiting.onstop=onstop;
cmdStop.focus();
return(false);
}

functionhideWait(){
glbBusy=false;
document.body.style.cursor="";
divWaiting.style.display="none";
try{clearTimeout(glbTimer);}catch(e){}
try{divWaiting.onstop();}catch(e){}
return(false);
}

functionstopExec(){hideWait();}

functionstartRecalcLine(){
varre="",re2="";
if(glbBusy)return;
glbBusy=true;

for(vari=0;ire+="

"+(i+1)+"

";
re2+="

";
}

divJSOutputLineNo.innerHTML=re;
divJSOutputPlus.innerHTML=re2;
divJSOutputPlus.buttons=newArray();

glbP=0;

showWait();
recalcLine();
return(false);

}


functionrecalcLine(){
varobjs,j;

objs=document.getElementsByTagName("div");
for(vari=glbP;iif(objs[i].className=="indent"){
j=parseInt(objs[i].offsetTop/14)-1;
divJSOutputPlus.childNodes[j].className="colsp";
divJSOutputPlus.childNodes[j].innerHTML="-";
divJSOutputPlus.childNodes[j].linkedDIV=objs[i];
divJSOutputPlus.childNodes[j].startIndex=j+1;
divJSOutputPlus.childNodes[j].endIndex=j+Math.round(objs[i].offsetHeight/14);
if(objs[i].innerHTML!="")divJSOutputPlus.childNodes[j].endIndex++;
divJSOutputPlus.childNodes[j].switchDIV=divJSOutputPlus.childNodes[j].onclick=switchDIV;
divJSOutputPlus.buttons.push(divJSOutputPlus.childNodes[j]);
}
}
spnProcess.innerHTML=parseFloat(glbP/objs.length*100).toFixed(2)+"%("+glbP+"/"+objs.length+")";
if(istopExec();
divJSOutput_onscroll();
}

functionswitchDIV(disp){
vary,obj;
if((this.className=="colsp"||disp=="hide")&&disp!="show"){
this.className="colsp2";
this.innerHTML="+";
for(vari=this.startIndex;idivJSOutputLineNo.childNodes[i].style.display="none";
divJSOutputPlus.childNodes[i].style.display="none";
}
this.linkedDIV.style.display="none";
}else{
this.className="colsp";
this.innerHTML="-";
this.linkedDIV.style.display="block";
for(vari=this.startIndex;idivJSOutputLineNo.childNodes[i].style.display="block";
divJSOutputPlus.childNodes[i].style.display="block";
if(divJSOutputPlus.childNodes[i].className=="colsp2"){
i=divJSOutputPlus.childNodes[i].endIndex-1;
}
}
}
divJSOutput_onscroll();
}

functioncollapseAll(index){
index=isNaN(parseInt(index))?0:parseInt(index);
if(!divJSOutputPlus.buttons)return;
if(index<0)index=0;
if(index>divJSOutputPlus.buttons.length)return;
for(vari=index;isetTimeout("collapseAll("+i+")");
}

functionexpandAll(index){
index=isNaN(parseInt(index))?0:parseInt(index);
if(!divJSOutputPlus.buttons)return;
if(index<0)index=0;
if(index>divJSOutputPlus.buttons.length)return;
for(vari=index;isetTimeout("expandAll("+i+")");
}


functioncore_analysis(){
varstr="",c="",lastState="",seq,intNextQuote,intTemp,intCount,intWordStart;
spnProcess.innerHTML=parseFloat(glbP/glbStr.length*100).toFixed(2)+"%("+glbP+"/"+glbStr.length+")";
for(vari=glbP;ic=glbStr.charAt(i);
str+=htmlEncode(c);
switch(c){
case"r":case"":case"t":
if(lastState=="rn"){str="";break;}
str=str.substring(0,str.length-htmlEncode(c).length);
if(lastState=="blank")break;
if(c.match(/W/)&&glbStr.charAt(i-1).match(/w/)){
str=str.replace(regKW,clKW).replace(regObj,clObj).replace(regMP,clMP);
}
str+=htmlEncode(c);
lastState="blank";
break;
case";":
if(str.match(/Wfor.*?(/i))break;
//attentionthere'snobreakhere
case"n":
if(lastState=="rn"){str="";break;}
outputLn(str);
str="";
lastState="rn";
if(i-glbP>200){
glbP=i+1;
glbTimer=setTimeout(core_analysis);
return;
}
break;
case""":
intNextQuote=i;
while(intNextQuote!=-1&&intNextQuoteintNextQuote=glbStr.indexOf(""",intNextQuote+1);
if(intNextQuote==-1||glbStr.charAt(intNextQuote-1)!="")break;
intCount=0;intTemp=intNextQuote;
while(glbStr.charAt(--intTemp)=="")intCount++;
if(intCount%2==0)break;
}
if(intNextQuote==-1)break;
str+=""+htmlEncode(glbStr.substring(i+1,intNextQuote))+""";
i=intNextQuote;
lastState="";
break;
case"'":
intNextQuote=i;
while(intNextQuote!=-1&&intNextQuoteintNextQuote=glbStr.indexOf("'",intNextQuote+1);
if(intNextQuote==-1||glbStr.charAt(intNextQuote-1)!="")break;
intCount=0;intTemp=intNextQuote;
while(glbStr.charAt(--intTemp)=="")intCount++;
if(intCount%2==0)break;
}
if(intNextQuote==-1)break;
str+=""+htmlEncode(glbStr.substring(i+1,intNextQuote))+"'";
i=intNextQuote;
lastState="";
break;
case"/":
if(glbStr.charAt(i+1)=="/"){
intNextQuote=i;
intNextQuote=glbStr.indexOf("rn",intNextQuote+1);
if(intNextQuote==-1)intNextQuote=glbStr.length;
str=str.substring(0,str.length-1);
str+="/"+htmlEncode(glbStr.substring(i+1,intNextQuote))
+"";
i=intNextQuote;
}elseif(glbStr.charAt(i+1)=="*"){
intNextQuote=i;
intNextQuote=glbStr.indexOf("*/",intNextQuote+1);
if(intNextQuote==-1)return;
str=str.substring(0,str.length-1);
str+="/"+htmlEncode(glbStr.substring(i+1,intNextQuote))
+"*/";
i=intNextQuote+1;
}elseif(str.match(/[=(][t]*//)){
intNextQuote=i;
while(intNextQuote!=-1&&intNextQuoteintNextQuote=glbStr.indexOf("/",intNextQuote+1);
if(intNextQuote==-1||glbStr.charAt(intNextQuote-1)!="")break;
intCount=0;intTemp=intNextQuote;
while(glbStr.charAt(--intTemp)=="")intCount++;
if(intCount%2==0)break;
}
if(intNextQuote==-1)break;
str+=""+htmlEncode(glbStr.substring(i+1,intNextQuote))
+"/";
i=intNextQuote;
lastState="";
}
lastState="";
break;
case"{":
outputLn(str);
str="";
seq=document.createElement("div");
seq.className="indent";
curRe.appendChild(seq);
curRe=seq;
lastState="rn";
if(i-glbP>200){
glbP=i+1;
glbTimer=setTimeout(core_analysis);
return;
}
break;
case"}":
outputLn(str.substring(0,str.length-1));
str="}";
lastState="";
curRe=curRe.parentNode;
break;
default:
if(c.match(/w/)&&glbStr.charAt(i-1).match(/W/)){intWordStart=i;}
if(c.match(/W/)&&glbStr.charAt(i-1).match(/w/)){
str=str.substring(0,str.length-htmlEncode(c).length);
str=str.replace(regKW,clKW).replace(regObj,clObj).replace(regMP,clMP)+htmlEncode(c);
}
lastState="";
break;
}
}

if(i==glbStr.length){
if(str!=""){outputLn(str);str="";}
stopExec();
}

}

functionoutputLn(theStr){
varseq,txt,fn;
if(html2txt(theStr).match(/^[trn]*$/))return;
seq=document.createElement("p");
seq.innerHTML=theStr;
curRe.appendChild(seq);

txt=html2txt(theStr);
if(!txt)return;
fn=txt.match(/function[trn]+([.w]+?)[trn]*(.*?)[trn]*{/);
if(fn){
glbFuntionNames.push(fn[1]);
selJSExport.options[selJSExport.options.length]=newOption(fn[0]+"}",fn[1]);
selJSExport.options[selJSExport.options.length-1].obj=seq;
}
fn=txt.match(/([.w]+?)[trn]*=[trn]*functionW*(.*?)[trn]*{/);
if(fn){
glbFuntionNames.push(fn[1]);
selJSExport.options[selJSExport.options.length]=newOption(fn[0]+"}",fn[1]);
selJSExport.options[selJSExport.options.length-1].obj=seq;
}
}

functionclKW(str){return(str.charAt(0)+""+str.substring(1)+"");}

functionclObj(str){return(str.charAt(0)+""+str.substring(1)+"");}

functionclMP(str){return(str.charAt(0)+""+str.substring(1)+"");}

functionclOP(str){return(str.charAt(0)+""+str.substring(1)+"");}


//------------------
//globalscripts
//------------------

functionmaximizeWindow(){
window.moveTo(0,0);
window.resizeTo(screen.availWidth,screen.availHeight);
}

functionhtmlEncode(strS){
return(strS.replace(/&/g,"&").replace(//g,">").replace(//g,"").replace(/
rn/g,"

"));
}

functionhtml2txt(strS){
return(strS.replace(/<.+?>/g,"").replace(//g,">").replace(//g,"").replace(/
>/g,"rn").replace(/&/g,"&"));
}






InputJS
CollapseAll
ExpandAll
ExportJS


PleaseInputtheJS:



/********************** Author:Hutia *********************/
window.onload=init; //------------------ //StaticVariable //-----
-------------
varKEYWORDS="abstractbreakbytecasecatchcharclasscons
tcontinuedefaultdeletedodoubleelseextendsfalsefinalfinallyf
loatforfunctiongotoifimplementsimportininstanceofintinterface&nbs
p;longnativenullpackageprivateprotectedpublicresetreturnshortstat
icsuperswitchsynchronizedthisthrowtransienttruetryvarvoidwh
ilewith"; varOBJECTS="AnchorAppletAreaArgumentsArrayBoolean 
;ButtonCheckboxCollectionCryptoDateDictionaryDocumentDriveDrivesElement
EnumeratorEventFileFileObjectFileSystemObjectFileUploadFolderFoldersFor
mFrameFunctionGlobalHiddenHistoryHTMLElementImageInfinityInputJav
aArrayJavaClassJavaObjectJavaPackageJSObjectLayerLinkMathMimeTypeNaviga
torNumberObjectOptionPackagesPasswordPluginPrivilegeManagerRandomRegExp
ScreenSelectStringSubmitTextTextareaURLVBArrayWindowWScript"
; varMETHODS_PROPERTIES="aboveabsacosactionactiveElementalertalinkCol
orallaltKeyanchoranchorsappCodeNameappletsapplyappNameappVersiona
rgumentsarityasinassignatanatan2atobavailHeightavailLeftavailTop&
nbsp;availWidthActiveXObjectbackbackgroundbelowbgColorbigblinkblurbold&
nbsp;borderborderWidthsbottombtoabuttoncallcalleecallercancelBubblecapt
ureEventsceilcharAtcharCodeAtcharsetcheckedchildrenclassesclassNameclea
rclearIntervalclearTimeoutclickclientInformationclientXclientYcloseclos
edcolorDepthcompilecompleteconcatconfirmconstructircontainscontextualco
okiecoscryptoctrlKeycurrentdatadefaultCharsetdefaultCheckeddefaultSelected&nb
sp;defaultStatusdefaultValuedescriptiondisableExternalCapturedisablePrivilegedocumentdoma
inEEchoelementelementsembedsenabledPluginenableExternalCaptureenablePri
vilegeencodingescapeevaleventexecexpexpandoFromPointfgColorfileNa
mefindfixedfloorfocusfontColorfontSizeformformsforwardframes 
;fromCharCodefromElementgetAttributegetgetClassgetDategetDaygetFullYear
getHoursgetMembergetMillisecondsgetMinutesgetMonthgetSecondsgetSelectiongetSlot&nbs
p;getTimegetTimezoneOffsetgetUTCDategetUTCDaygetUTCFullYeargetUTCHoursgetUTCMillise
condsgetUTCMinutesgetUTCMonthgetUTCSecondsgetWindowgetYearglobalgoHandleEvent
HeighthashhiddenhistoryhomehosthostNamehrefhspaceidid
signoreCaseimagesindexindexOfinnerinnerHTMLinnerTextinnerWidthinsertAdj
acentHTMLinsertAdjacentTextisFiniteisNANitalicsjavajavaEnabledjoinkeyCode&nbs
p;LinksLN10LN2LOG10ELOG2ElanglanguagelastIndexlastIndexOflastMatc
hlastModifiedlastParenlayerslayerXlayerYleftleftContextlengthlink
linkColorloadlocationlocationBarloglowsrcMAX_VALUEMIN_VALUEmargins 
;matchmaxmenubarmethodmimeTypesminmodifiersmoveAbovemoveBelowmoveBy&nbs
p;moveTomoveToAbsolutemultilineNaNNEGATIVE_INFINITYnamenavigatenavigator 
;netscapenextnumberoffscreenBufferingoffsetoffsetHeightoffsetLeftoffsetParent
offsetTopoffsetWidthoffsetXoffsetYonabortonbluronchangeonclickondblclick 
;ondragdroponerroronfocusonHelponkeydownonkeypressonkeyuponloadonmoused
ownonmousemoveonmouseoutonmouseoveronmouseuponmoveonresetonresizeonsubmit&nbs
p;onunloadopenopeneroptionsouterHeightouterHTMLouterTextouterWidthPOSIT
IVE_INFINITYPIpaddingspageXpageXOffsetpageYpageYOffsetparentparentEleme
ntparentLayerparentWindowparseparseFloatparseIntpathnamepersonalbarpixelDepth
platformpluginspopportpowpreferencepreviousprintpromptproto
colprototypepushrandomreadyStatereasonreferrerrefreshreleaseEventsreloa
dremoveAttributeremoveMemberreplaceresizeByresizeToreturnValuereverseright&nb
sp;rightcontextroundSQRT1_2SQRT2screenXscreenYscrollscrollbarsscrollBy&
nbsp;scrollIntoViewscrollTosearchselectselectedselectedIndexselfsetAttributes
etDaysetFullYearsetHotkeyssetHourssetIntervalsetMembersetMillisecondssetMinut
essetMonthsetResizablesetSecondssetSlotsetTimesetTimeoutsetUTCDatesetUTCFullY
earsetUTCHourssetUTCMillsecondssetUTCMinutessetUTCMonthsetUTCSecondssetYearse
tZOptionsshiftshiftKeysiblingAbovesiblingBelowsignTextsinslicesmallsort
sourcesourceIndexsplicesplitsqrtsrcsrcElementsrcFilterstatusstatu
sbarstopstrikestylesubsubmitsubstrsubstringsuffixessunsupsy
stemLanguageTYPEtagNametagstainttaintEnabledtantargettesttext&nbs
p;titletoElementtoGMTStringtoLocaleStringtoLowerCasetoolbartoptoStringtoUpper
CasetoUTCStringtypetypeOfUTCunescapeunshiftuntaintunwatchuserAgent 
;userLanguagevaluevalueOfvisibilityvlinkColorvspacewatchwhichwidth 
;windowwritewritelnxyzIndex"; varOPS="!$%
&*+-///:<=>?[]
^|~isnewsizeoftypeofunchecked"; var
regKW=newRegExp("(W"+KEYWORDS.replace(//g,"$)|(W")+"$)
","g"); varregObj=newRegExp("(W"+OBJECTS.replace(//g,"$)|
(W")+"$)","g"); varregMP=newRegExp("
(W"+METHODS_PROPERTIES.replace(//g,"$)|(W")+"$)
","g"); //varregOP=newRegExp("(W"+OPS.replace(//g,"$)|(W")
+"$)","g"); //------------------ //GlobalVariables //--
----------------
vardivJSInput,txtJSInput,divMain,divJSOutputLineNo,divJSOutputPlus,divJSOutput,
divWaiting; varspnProcess,cmdStop,divJSExport,selJSExport,divJSExportContent;
3; varglbStr,glbP,glbRe,curRe,glbTimer,glbBusy,glbFuntionNames; &
#10; functioninit()
{ //initglobalvariables divJSInput=document.getElementById
("divJSInput"); txtJSInput=document.getElementById
("txtJSInput"); divMain=document.getElementById
("divMain"); divJSOutputLineNo=document.getElementById
("divJSOutputLineNo"); divJSOutputPlus=document.getElementById
("divJSOutputPlus"); divJSOutput=document.getElementById
("divJSOutput"); divWaiting=document.getElementById
("divWaiting"); spnProcess=document.getElementById
("spnProcess"); cmdStop=document.getElementById
("cmdStop"); divJSExport=document.getElementById
("divJSExport"); selJSExport=document.getElementById
("selJSExport"); divJSExportContent=document.getElementById
("divJSExportContent"); //initwindowstate maximizeW
indow(); divMain.style.width=document.body.clientWidth-
4; divMain.style.height=document.body.clientHeight-
26; divJSOutput.style.width=document.body.clientWidth-
52; //initglobalevents divJSOutputLineNo.onse
lectstart=divJSOutputLineNo.onselect=divJSOutputPlus.onselectstart=divJSOutputPlus.onselect=cancelEvents; divJ
SOutput.onscroll=divJSOutput_onscroll; divJSInput.onkeydown=divJSInput_keydown;  
;divJSExport.onkeydown=divJSExport_keydown; } //------------------
//eventscripts //------------------ functioncancelEvents(e)
{ vare=window.event?window.event:e; e.returnValue=false; return
(false); } functiondivJSInput_keydown(e){ vare=window.event?
window.event:e; varsrcEle=e.srcElement?
e.srcElement:e.target; varsel; if(e.keyCode==27)hideJSInput(); if
(e.keyCode==13&&e.ctrlKey)execJSInput(); if(e.keyCode==9&&srcEle==txtJSInput)
{ document.selection.createRange().text="t";return
(false);//notsupportFF } }
functiondivJSExport_keydown(e){ vare=window.event?
window.event:e; varsrcEle=e.srcElement?
e.srcElement:e.target; varsel; if(e.keyCode==27)hideJSExport(); if
(e.keyCode==13&&e.ctrlKey)hideJSExport(); } functiondivJSOutput_onscroll()
{ divJSOutputLineNo.scrollTop=divJSOutputPlus.scrollTop=divJSOutput.scrollTop; }
//------------------ //functionalscripts //-----------
------- functionshowJSInput(){ if(glbBusy)return; hideJSExport
(); with(divJSInput.style){ display="block"; left=
(document.body.clientWidth-divJSInput.offsetWidth)/2; top=(document.body.clientHeight-
divJSInput.offsetHeight)/2; } txtJSInput.focus
(); return(false); } functionshowJSExport()
{ if(glbBusy)return; hideJSInput(); with(divJSExport.style)
{ display="block"; left=(document.body.clientWidth-
divJSExport.offsetWidth)/2; top=(document.body.clientHeight-
divJSExport.offsetHeight)/2; }
divJSExportContent.style.display="none"; selJSExport.style.display="block"
; selJSExport.focus(); return(false); }
functionhideJSInput(){ divJSInput.style.display="none"; }
functionhideJSExport(){ divJSExport.style.display="none"; }
functionexecJSInput(){ hideJSInput
(); divJSOutput.innerHTML=""; divJSOutputLineNo.innerHTML=""
;; divJSOutputPlus.innerHTML=""; glbStr=txtJSInput.value; &n
bsp;glbP=0; glbFuntionNames=newArray(); curRe=glbRe=document.createElement
("div"); divJSOutput.appendChild
(glbRe); glbRe.className="codeRoot"; while
(selJSExport.options.length>0)selJSExport.options[0]=null; showWait
(startRecalcLine); core_analysis(); } functionexecJSExport()
{ varfns=newArray(),fcs=newArray(),str; for
(vari=0;i{ fns.push(selJSExport.options[i].value); str=selJSExport.options
[i].obj.outerHTML; try{ str+=selJSExport.options
[i].obj.nextSibling.outerHTML; str+=selJSExport.options
[i].obj.nextSibling.nextSibling.outerHTML; }catch(e){} fcs.push
(str); } } if(fns.length==0)
return; divJSExportContent.style.display="block"; selJSExport.style.d
isplay="none"; divJSExportContent.innerHTML=fcs.join
("rn

rn"); } functionexecJSExport_Dep()
{ varfns=newArray(),fcs=newArray(),str,regFNs=newArray
(),needDepthTest; for(vari=0;i{ if(selJSExport.options[i].selected){ fns.push(selJSExport.options
[i].value); try{ str=selJSExport.options
[i].obj.nextSibling.outerHTML; }catch(e){} fcs.push
(str); } } if(fns.length==0)
return; divJSExportContent.style.display="none"; selJSExport.style.di
splay="block"; needDepthTest=false; for
(vari=0;i{ for(j=0;j(glbFuntionNames[i].replace(/./g,"."))){ selJSExport.options
[i].selected=true; needDepthTest=true; break;&#
13; } } } } if
(needDepthTest)execJSExport_Dep(); } functionshowWait(onstop)
{ glbBusy=true; document.body.style.cursor="wait"; wit
h(divWaiting.style){ display="block"; left=(document.body.clientWidth-
divWaiting.offsetWidth)/2; top=(document.body.clientHeight-divWaiting.offsetHeight)/2; }
spnProcess.innerHTML="0.00%(0/0)
"; divWaiting.onstop=onstop; cmdStop.focus(); return(false); }
functionhideWait()
{ glbBusy=false; document.body.style.cursor=""; divWaiting.style.displ
ay="none"; try{clearTimeout(glbTimer);}catch(e){} try{divWaiting.onstop();}catch(e)
{} return(false); } functionstopExec(){hideWait();}
functionstartRecalcLine()
{ varre="",re2=""; if(glbBusy)
return; glbBusy=true; for(vari=0;i(divJSOutput.scrollHeight/14+200);i++){ re+="

"+(i+1)
+"

"; re2+="

"; }
divJSOutputLineNo.innerHTML=re; divJSOutputPlus.innerHTML=re2;
divJSOutputPlus.buttons=newArray(); glbP=0; showWait
(); recalcLine(); return(false); }
functionrecalcLine()
{ varobjs,j; objs=document.getElementsByTagName
("div"); for(vari=glbP;i(objs[i].className=="indent"){ j=parseInt(objs[i].offsetTop/14)-
1; divJSOutputPlus.childNodes
[j].className="colsp"; divJSOutputPlus.childNodes[j].innerHTML="-
"; divJSOutputPlus.childNodes[j].linkedDIV=objs
[i]; divJSOutputPlus.childNodes
[j].startIndex=j+1; divJSOutputPlus.childNodes[j].endIndex=j+Math.round(objs[i].offsetHeight/14)
+1; divJSOutputPlus.childNodes[j].switchDIV=divJSOutputPlus.childNodes
[j].onclick=switchDIV; divJSOutputPlus.buttons.push(divJSOutputPlus.childNodes
[j]); } } spnProcess.innerHTML=parseFloat(glbP/objs.length*100).toFixed
(2)+"%("+glbP+"/"+objs.length+")"; if
(i(); divJSOutput_onscroll(); } functionswitchDIV(disp)
{ vary,obj; if((this.className=="colsp"||disp=="hide")
&&disp!="show")
{ this.className="colsp2"; this.innerHTML="+"; &
nbsp;for(vari=this.startIndex;i[i].style.display="none"; divJSOutputPlus.childNodes
[i].style.display="none"; }
this.linkedDIV.style.display="none"; }else
{ this.className="colsp"; this.innerHTML="-
"; this.linkedDIV.style.display="block"; for
(vari=this.startIndex;i[i].style.display="block"; divJSOutputPlus.childNodes
[i].style.display="block"; if(divJSOutputPlus.childNodes
[i].className=="colsp2"){ i=divJSOutputPlus.childNodes[i].endIndex-
1; } } } divJSOutput_onscroll(); }
functioncollapseAll(index){ index=isNaN(parseInt(index))?0:parseInt
(index); if(!divJSOutputPlus.buttons)return; if(index<0)index=0; if
(index>divJSOutputPlus.buttons.length)return; for
(vari=index;i("hide"); setTimeout("collapseAll("+i+")"); }
functionexpandAll(index){ index=isNaN(parseInt(index))?0:parseInt
(index); if(!divJSOutputPlus.buttons)return; if(index<0)index=0; if
(index>divJSOutputPlus.buttons.length)return; for
(vari=index;i("show"); setTimeout("expandAll("+i+")"); }
functioncore_analysis()
{ varstr="",c="",lastState="",seq,intNextQuo
te,intTemp,intCount,intWordStart; spnProcess.innerHTML=parseFloat
(glbP/glbStr.length*100).toFixed(2)+"%
("+glbP+"/"+glbStr.length+")"; for
(vari=glbP;i(c); switch(c)
{ case"r":case"":case"t":
if(lastState=="rn"){str="";break;}
str=str.substring(0,str.length-htmlEncode(c).length); if
(lastState=="blank")break; if(c.match(/W/)&&glbStr.charAt(i-1).match(/
w/)){ str=str.replace(regKW,clKW).replace(regObj,clObj).replace
(regMP,clMP); } str+=htmlEncode
(c); lastState="blank"; break; &nb
sp;case";": if(str.match(/Wfor.*?(/i))
break; //attentionthere'snobreakhere &nbs
p;case"n": if(lastState=="rn"){str="";break;}
outputLn
(str); str=""; lastState="rn";&
#13; if(i-glbP>200)
{ glbP=i+1; glbTimer=setTimeout
(core_analysis); return; }
break; case""":  
;intNextQuote=i; while(intNextQuote!=-1&&intNextQuote{ intNextQuote=glbStr.indexOf
(""",intNextQuote+1); if(intNextQuote==-1||glbStr.charAt(intNextQuote
-1)!="")
break; intCount=0;intTemp=intNextQuote; w
hile(glbStr.charAt(--intTemp)=="")intCount++; if(intCount%2==0)
break; } if(intNextQuote==-1)
break; str+=""+htmlEncode
(glbStr.substring(i+1,intNextQuote))
+"""; i=intNextQuote; lastSta
te=""; break; case"'":
intNextQuote=i; while(intNextQuote!=-1&&intNextQuote{ intNextQuote=glbStr.indexOf
("'",intNextQuote+1); if(intNextQuote==-1||glbStr.charAt(intNextQuote-1)!
="")
break; intCount=0;intTemp=intNextQuote; w
hile(glbStr.charAt(--intTemp)=="")intCount++; if(intCount%2==0)
break; } if(intNextQuote==-1)
break; str+=""+htmlEncode
(glbStr.substring(i+1,intNextQuote))
+"'"; i=intNextQuote; lastState=&q
uot;"; break; case"/":  
;if(glbStr.charAt(i+1)=="/")
{ intNextQuote=i; intNextQuote=glbStr.indexOf
("rn",intNextQuote+1); if(intNextQuote==-1)
intNextQuote=glbStr.length; str=str.substring(0,str.length-
1); str+="/"+htmlEncode
(glbStr.substring(i+1,intNextQuote))
+""; i=intNextQuote; }
elseif(glbStr.charAt(i+1)=="*")
{ intNextQuote=i; intNextQuote=glbStr.indexOf
("*/",intNextQuote+1); if(intNextQuote==-1)
return; str=str.substring(0,str.length-
1); str+="/"+htmlEncode
(glbStr.substring(i+1,intNextQuote))
+"*/"; i=intNextQuote+1; }
elseif(str.match(/[=(][t]*//))
{ intNextQuote=i; while(intNextQuote!=-
1&&intNextQuote("/",intNextQuote+1); if(intNextQuote==-1||glbStr.charAt
(intNextQuote-1)!="")
break; intCount=0;intTemp=intNextQuote; &
nbsp;while(glbStr.charAt(--intTemp)=="")intCount++; if
(intCount%2==0)break; } if(intNextQuote==-1)
break; str+=""+htmlEncode
(glbStr.substring(i+1,intNextQuote))
+"/"; i=intNextQuote;
lastState=""; }
lastState=""; break; case&n
bsp;"{": outputLn
(str); str=""; seq=document.createElement
("div"); seq.className="indent"; curRe.
appendChild
(seq); curRe=seq; lastState="rn"; &nbs
p;if(i-glbP>200)
{ glbP=i+1; glbTimer=setTimeout
(core_analysis); return; }
break; case"}
": outputLn(str.substring(0,str.length-
1)); str="}
"; lastState=""; curRe=curRe.parentNod
e; break; default: if(c.match(/w/)
&&glbStr.charAt(i-1).match(/W/)){intWordStart=i;} if(c.match(/W/)
&&glbStr.charAt(i-1).match(/w/)){ str=str.substring(0,str.length-htmlEncode
(c).length); str=str.replace(regKW,clKW).replace(regObj,clObj).replace(regMP,clMP)
+htmlEncode(c); }
lastState=""; break; }
} if(i==glbStr.length){ if(str!="")
{outputLn(str);str="";} stopExec(); }
} functionoutputLn(theStr)
{ varseq,txt,fn; if(html2txt(theStr).match(/^[trn]*$/))
return; seq=document.createElement
("p"); seq.innerHTML=theStr; curRe.appendChild
(seq); txt=html2txt(theStr); if(!txt)return; fn=txt.match
(/function[trn]+([.w]+?)[trn]*(.*?)[trn]*{/); if(fn)
{ glbFuntionNames.push(fn[1]); selJSExport.options[selJSExport.options.length]
=newOption(fn[0]+"}",fn[1]); selJSExport.options[selJSExport.options.length-
1].obj=seq; } fn=txt.match(/([.w]+?)[trn]*=[trn]*functionW*(.*?)
[trn]*{/); if(fn){ glbFuntionNames.push(fn
[1]); selJSExport.options[selJSExport.options.length]=newOption(fn[0]+"}",fn
[1]); selJSExport.options[selJSExport.options.length-1].obj=seq; } }
functionclKW(str){return(str.charAt(0)
+""+str.substring(1)+"");}
functionclObj(str){return(str.charAt(0)
+""+str.substring(1)+"");}
functionclMP(str){return(str.charAt(0)
+""+str.substring(1)+"");}
functionclOP(str){return(str.charAt(0)
+""+str.substring(1)+"");}
//------------------ //globalscripts //------------------
functionmaximizeWindow(){ window.moveTo(0,0); window.resizeTo
(screen.availWidth,screen.availHeight); } functionhtmlEncode(strS){ return
(strS.replace(/&/g,"&").replace(/(/>/g,">").replace(//g,"").replace(/
rn/g,"

")); } functionhtml2txt(strS){ return
(strS.replace(/<.+?>/g,"").replace(/</g,"<").replace
(/>/g,">").replace(//g,"").replace(/
/g,"rn").replace
(/&/g,"&")); }






FunctionList:


<selectid="selJSExport"multiplesize="2">











Processing...






相关推荐