JavaScript code formatting and syntax coloring

Source: Internet
Author: User
Tags array comments net variables visibility window domain domain name
javascript| Syntax

Have seen a few JS code format, oneself also write a, hehe, the advantage is can deal with the super long JS and will not crash ...

IE only

Run Code Box

<html><head><title>jser </title><meta http-equiv= "Content-type" content= "text/html"; charset=gb2312 "/><style>/* Global CSS */* {padding:0px; margin:0px; font-size:13px; font-family:arial song Body;} body {overflow:auto; border:0px-none black; background-color:buttonface;} Li {margin:0px 0px 0px 40px; padding:2px 4px;} /* Class CSS */.quote {color: #999;}. Comments {color: #009090;}. Indent {margin-left:25px}. regexp {color: #F000F0;} /* Identified CSS */#divTools {height:20px; border-bottom:1px solid #555; padding-left:15px;} #divTools a {color:navy; text-decoration:none; height:20px; line-height:20px; padding:0px 25px;} #divTools a:hover {color:white; background-color:navy; text-decoration:none; height:20px; line-height:20px;} #divJSInput {display:none; width:600px; height:450px; border:2px outset buttonface; position:absolute; Background-color:buttonface; Z-index:2; } #divJSInputTitle {color:white; background-color:navy; height:20px; line-height:20px; padding:0px 10px; Cursor:default; } #txtJSInput {width:598px; height:406px; overflow:auto; padding:4px 8px; background-color:white;} #divJSInputBar {height:24px; padding:0px 4px;} #divJSInputBar input {width:110px; height:22px; border:1px solid #555; line-height:20px;} #divJSOutput {background-color:white; border:1px inset buttonface; width:100% height:500px; overflow:auto;} #divWaiting {display:none; width:400px; height:60px; border:1px solid buttonface; position:absolute; Background-color: #E0F0F0; Z-index:3; Text-align:center; padding-top:10px; #divWaiting input {width:140px; height:22px; border:1px solid #555; line-height:20px; cursor:default; margin-top:4px;} </style><script type= "Text/javascript" >/********************** Author:hutia *********************/ window.onload=init;//------------------//Static variable//------------------var keywords= "Abstract Break byte Catch Char class const continue default delete do double else extends false final finally float for function Goto if implements import in instanceof int interface long native NULL package private protected Pub LIC reset return short static super switch synchronized this throw transient true try Var void while with "; var objects=" Chor Applet area Arguments Array Boolean Button Checkbox Collection Crypto Date Dictionary Document Drive drives Element E Numerator Event File fileobject FileSystemObject fileupload Folder Folders Form Frame Function Global Hidden History Htmle Lement Image Infinity Input javaarray javaclass javaobject javapackage jsobject Layer Link Math mimetype Navigator Object Option Packages Password Plugin privilegemanager Random RegExp screen Select String Submit Text Textarea URL Vbarra y window WScript "; var methods_properties=" above ABS ACOs action activeelement alert alinkcolor all Altkey anchor anchors a Ppcodename applets apply appName appversion arguments arity ASIN assign Atan atan2 atob availheight availleft av Ailwidth ActiveXObject bACK background below bgcolor big blink blur bold Border borderwidths the bottom button call Btoa callee caller CA Ptureevents ceil charAt charcodeat CharSet checked children classes ClassName clear Clearinterval cleartimeout Click Clien Tinformation ClientX ClientY Close closed colordepth compile complete concat confirm Constructir contains contextual cook IE cos crypto ctrlkey current data defaultcharset defaultchecked defaultselected defaultstatus defaultvalue description di Sableexternalcapture disableprivilege document Domain E Echo element elements embeds Enabledplugin Enableexternalcapture Enableprivilege encoding escape eval event exec exp expando frompoint fgcolor fileName Find fixed floor focus fontcolor F Ontsize form Forms forward Frames fromCharCode fromelement getattribute get getclass getDate getday getfullyear GetMember getmilliseconds getminutes getmonth getseconds getselection getslot getTime gettimezoneoffset getUTCDate GetUT Cday getUTCFullYear GETUTCHours getutcmilliseconds getutcminutes getutcmonth getutcseconds getWindow getyear Global go handleevent Height hash Hidd En history Home host hostName href hspace ID IDs ignoreCase Images index indexOf inner innerHTML innertext innerwidth inse rtadjacenthtml insertAdjacentText isfinite isNaN italics Java javaenabled join KeyCode Links LN10 LN2 log10e LOG2E lang l Anguage lastindex lastindexof lastmatch lastmodified lastparen layers Layerx layery left leftcontext length link linkColor Load location Locationbar log lowsrc max_value min_value margins Match MAX menubar method mimetypes MIN modifiers Moveab Ove Movebelow Moveby moveTo movetoabsolute Multiline NaN negative_infinity name navigate navigator Netscape Next number O Ffscreenbuffering offsetheight offsetleft offsetparent offsettop offsetwidth offsetX offsetY onabort onblur Onchan GE onclick ondblclick ondragdrop onerror onfocus onhelp onkeydown onkeypress onkeyup onload onmousedown onmousemove Onmou Seout onmouseover OnmouseUp OnMove onreset onresize onsubmit onunload Open Opener options outerheight outerhtml outertext outerwidth positive_infi Nity PI paddings Pagex pagexoffset pagey pageyoffset parent parentelement parentlayer ParentWindow Parse parseFloat Int pathname Personalbar pixeldepth Platform plugins pop port POW preference previous Print prompt protocol prototype pus H Random readyState reason referrer Refresh releaseevents reload removeattribute removemember replace Resizeby Resizeto re Turnvalue Reverse right rightcontext round sqrt1_2 SQRT2 screenX screenY scroll scrollbars scrollby scrollintoview scroll To search Select selected SelectedIndex self setattribute setday setfullyear sethotkeys sethours setinterval setmember SE Tmilliseconds setminutes setmonth setresizable setseconds setslot settime settimeout setUTCDate setUTCFullYear setUTCHours setutcmillseconds setutcminutes setutcmonth setutcseconds setyear setzoptions shift ShiftKey SiblingAbove si Blingbelow signtext Sin Slice smallsORT source sourceindex Splice split sqrt src srcelement srcfilter status StatusBar Stop strike style sub Submit substr Su bstring suffixes Sun sup systemlanguage TYPE tagName tags taint taintenabled tan target Test text title Toelement TOGMTST Ring tolocalestring tolowercase Toolbar top toString touppercase toutcstring type typeOf UTC unescape unshift untaint Unwa TCH useragent userlanguage value valueof visibility vlinkcolor vspace Watch-which width window write writeln x y zindex "; var ops= "! $% & * +-//: < = >? [ ] ^ | ~ is new sizeof typeof unchecked "; var regkw=new RegExp (" \\w "+keywords.replace (//g," $) | ( \\w ") +" $) "," G "); var regobj=new RegExp (" (\\w +objects.replace (//g, "$) | ( \\w ") +" $) "," G "); var regmp=new RegExp (" (\\w +methods_properties.replace (//g, "$) | ( \\w ") +" $) "," G ");//var regop=new RegExp (" \\w "+ops.replace (//g," $) | ( \\w ") +" $) "," G "); var colorkw=" Blue "; var colorobj=" Red "; var colormp=" #FF8000 "; var colorop=" #004000 ";//-------------- ----//Global variables//------------------var divjsinput, Txtjsinput, Divjsoutput, divwaiting, Spnprocess;var glbstr, GLBP, Glbre, Curre, GlbTimer; function init () {//INIT global Variables Divjsinput=document.getelementbyid ("Divjsinput"); txtjsinput= document.getElementById ("Txtjsinput"); Divjsoutput=document.getelementbyid ("Divjsoutput"); Divwaiting=document.getelementbyid ("divwaiting"); Spnprocess=document.getelementbyid ("spnprocess"); init window state Maximizewindow (); Divjsoutput.style.width=document.body.clientwidth-2; divjsoutput.style.height=document.body.clientheight-26; Init global events Divjsinput.onkeydown=divjsinput_keydown;} ------------------//Event scripts//------------------function Divjsinput_keydown (e) {var e=window.event? Window.event:e; var srcele=e.srcelement?e.srcelement:e.target; var sel; 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);/Not SUpport FF}}//------------------//Functional scripts//------------------function showjsinput () {with ( Divjsinput.style) {display= "block"; left= (Document.body.clientwidth-divjsinput.offsetwidth)/2; top= (Document.body.clientheight-divjsinput.offsetheight)/2; } txtjsinput.focus (); return (false); function Hidejsinput () {divjsinput.style.display= "none";} function Execjsinput () {hidejsinput (); Divjsoutput.innerhtml= ""; Glbstr=txtjsinput.value.replace (/\r\n[\t]+/gi, "\ r \ n"). Replace (/(\ r \ n) +/gi, "\ r \ n"); Glbp=0; Curre=glbre=document.createelement ("div"); Divjsoutput.appendchild (Glbre); Glbre.classname= "Coderoot"; ShowWait (); Core_analysis ();} function showwait () {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)" return (false);} function Stopexec () {document.body.style.cursor= ""; DivWaiting.style.disPlay= "None"; Try{cleartimeout (Glbtimer);} catch (e) {} return (false);} function core_analysis () {var str= "", c= "", laststate= "", seq, Intnextquote, IntTemp, intcount, Intwordstart, spnprocess. Innerhtml=parsefloat (glbp/glbstr.length*100). toFixed (2) + "% (" +glbp+ "/" +glbstr.length+ ")"; for (Var i=glbp;i<glbstr.length;i++) {C=glbstr.charat (i); Str+=htmlencode (c); Switch (c) {case "\ r": Case "": Case "T": if (laststate== "\ r \ n") {str= ""; break;} 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); } break; Case "\ n": Case ";": if (laststate== "\ r \ n") {str= ""; break;} Outputln (str); Str= ""; Laststate= "\ r \ n"; if (i-glbp>200) {glbp=i+1; Glbtimer=settimeout (core_analysis); Return } break; Case "\" ": intnextquote=i; while (intnextquote!=-1&&intnextquote<glbstr.length) {intNextquote=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+= "<span class=\" quote\ ">" +htmlencode (glbstr.substring (i+1,intnextquote)) + "<\/span>\"; I=intnextquote; Laststate= ""; Break Case "\": intnextquote=i; while (intnextquote!=-1&&intnextquote<glbstr.length) {intnextquote=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+= "<span class=\" quote\ ">" +htmlencode (glbstr.substring (i+1,intnextquote)) + "<\/span>\"; I=intnextquote; Laststate= ""; Break Case "\/": if (Glbstr.charat (i+1) = = "\/") {INTNExtquote=i; Intnextquote=glbstr.indexof ("\ r \ n", intnextquote+1); if (intnextquote==-1) intnextquote=glbstr.length; Str=str.substring (0,str.length-1); str+= "<span class=\" comments\ ">\/" +htmlencode (glbstr.substring) + "<\/span>"; I=intnextquote; }else if (Glbstr.charat (i+1) = = "*") {intnextquote=i; Intnextquote=glbstr.indexof ("*\/", intnextquote+1); if (intnextquote==-1) return; Str=str.substring (0,str.length-1); str+= "<span class=\" comments\ ">\/" +htmlencode (glbstr.substring) + "I+1,intnextquote"; i=intnextquote+1; }else if (Str.match (/[= (] [\t]*\//)) {intnextquote=i; while (intnextquote!=-1&&intnextquote<glbstr.length) {intnextquote=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+= "<span class=\" regexp\ ">" +htmlencode (glbstr.substring (i+1,intnextquote)) + "<\/span>\/"; I=intnextquote; Laststate= ""; } laststate= ""; Break Case "{": Outputln (str); Str= ""; Seq=document.createelement ("div"); Seq.classname= "Indent"; Curre.appendchild (seq); Curre=seq; Laststate= "\ r \ n"; 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 (); }}function outputln (thestr) {var seq=document.createelement ("P"); seq.innerhtml=thestr; curre.appendchild (seq);} function clkw (str) {return (Str.charat (0) +str.substring (1). FontColor (colorkw)); function Clobj (str) {return (Str.charat (0) +str.substring (1). FontColor (Colorobj)); function CLMP (str) {return (Str.charat (0) +str.substring (1). FontColor (COLORMP)); function Clop (str) {return (Str.charat (0) +str.substring (1). FontColor (Colorop)); ------------------//Global scripts//------------------function Maximizewindow () {Window.moveto (0,0); Window.resizeto (screen.availwidth,screen.availheight);} function HtmlEncode (STRs) {return (Strs.replace (/&/g, "&"). Replace (/</g, "<"). Replace (/>/g, ">") . replace (//g, " "). Replace (/\r\n/g, "<br\/>")); </script></head><body><div id= "Divtools" ><a href= "#" >input JS</a></div> <div id= "Divjsinput" > <div id= "divjsinputtitle" >please Input the js:</div> <textarea "id=" Txtjsinput ">document.write (' <script type= "Text/javascript"  src= "/js/flashobject.js" ></scr ' + ' ipt> ') ; Function runcode () {if (1==arguments.length) try{event=arguments[0]; catch (E) {};var code= (event.target| | event.srcelement). Parentnode.childnodes[0].value;var newwin=window.open (', ', ', '); newwin.opener= Nullnewwin.document.write (code); Newwin.document.close ();}; Function mm_findobj (n,d) {var p,i,x;if (!d) d=document;if ((P=n.indexof ("?")) >0&&parent.frames.length) {d=parent.frames[n.substring (p+1)].document;n=n.substring (0,p);}; if (!) ( X=d[n]) &&d.all) x=d.all[n];for (i=0;! x&&i<d.forms.length;i++) X=d.forms[i][n];for (i=0;! x&&d.layers&&i<d.layers.length;i++) X=mm_findobj (n,d.layers[i].document); if (!x&& d.getElementById) X=d.getelementbyid (n);return x;}; Function mm_showhidelayers () {var i,p,v,obj,args=mm_showhidelayers.arguments;for (i=0;i<) ( args.length-2); i+=3) if ((Obj=mm_findobj (args[i))!=null) {v=args[i+2];if (Obj.style) {obj=obj.style;v= (v== ' show ')? ' Visible ':(v= ' hide ')? ' Hidden ': V;};o Bj.visibility=v;}; Function adbanner () {this.htmlcode= ""; this.href= ""; this.imgsrc= ""; this.imgwidth= ""; this.imgheight= ""; This.imgalt= ""; this.imgborder= ""; this.weight=1;this.place=1this.type=1;this.id=0; Function creatbanners (Abanners,anum) {for (var i=0;i<anum;i++) {Abanners[i]=new adbanner ();};}; Function showbanner (Aplace,atype,abannerid) {var amount=adbanners.length;var includelist=new  array (amount); if (!document.usedbanners) {Document.usedbanners=new array (amount); for (var i=0;i <amount;i++) document.usedbanners[i]=-1;}; Var usedlist=document.usedbanners;if (arguments.length==2) {var j=0;var sum=0;for (var i=0;i <amount;i++) {if (Adbanners[i].place==aplace&&adbanners[i].type==atype) {if (usedlist[i]!=i) { Includelist[j]=i;j++;sum=sum+adbanners[i].weight;};;}; if (sum<=0) Return ;var rndnum=math.round (Math.random () *sum); i=0;j=0;while (true) {j=j+adbanners[includelist[i]].weight;if (j>=rndnum) break;i++;}; I=includelist[i];}; Else {if (Abannerid>=0&&abannerid<amount) i=abannerid;else return ;}; Usedlist[i]=i;if (adbanners[i].htmlcode== "") document.write (' <a href= ' +adbanners[i].href+ ' " target") =_blank><img src= "' +adbanners[i].imgsrc+ '" " width=" ' +adbanners[i].imgwidth+ ' " HEIGHT=" ' + adbanners[i].imgheight+ ' " alt=" ' +adbanners[i].imgalt+ ' " border=" ' +adbanners[i].imgborder+ ' "></ A> '); Else document.write (Adbanners[i].htmlcode);d ocument.write (' <script src=/common/jsbanner/ Redirect.asp?action=visit&id= ' +adbanners[i].id+ '  ></s ' + ' cript> ')};var ADBanners=new  array (); Creatbanners (adbanners,9); Adbanners[0].htmlcode= ' <object classid= ' clsid:d27cdb6e-ae6d-11cf-96b8-444553540000 " codebase=" Swflash.cab "; Adbanners[1].href= "http://www.chinaok.net.cn"; Adbanners[1].imgwidth= "208"; Adbanners[1].imgheight= "32"; ADBanners[1].imgalt= "Build station, revision, promotion, find eurofilm power"; adbanners[1].weight=10; adbanners[1].place=4; adbanners[1].type=4; adbanners[1].id=42; Adbanners[2].htmlcode= ' <script type= ' Text/javascript ">google_ad_client = " pub-5841412030047197 ";google_alternate_color = " CCCCD4 "; google_ad_width = 728;google_ad_ height = 90;google_ad_format =  "728x90_as"; google_ad_channel = "7977407778"; google_ad_ type =  "Text_image";google_color_border =  "6699CC";google_color_bg =  "003366"; google_color_link =  "FFFFFF";google_color_url =  "Aecceb";google_color_text =  " Aecceb "</script><script type=" Text/javascript " src=" http://pagead2.googlesyndication.com/ Pagead/show_ads.js "></script>"; adbanners[2].weight=20; adbanners[2].place=6; adbanners[2].type=6; adbanners[2].id=46; Adbanners[3].htmlcode= ' <a target=_blank href=http://www.mydeskcity.com/2006dvd/index.htm><b ><font color=red> Classic Desktop 2006 DVD Resource CD </font></b></a><br><a href=http:// Www.jietusoft.com/case_tw.html target=_blank><b> three-dimensional panoramic roaming appreciation </b></a><br><a  href=http://ale.2006.163.com/blog target=_blank><font color=red> World Cup topic, invite you to talk about </font ></A> '; adbanners[3].weight=10; adbanners[3].place=10; adbanners[3].type=7; adbanners[3].id=52; Adbanners[4].imgsrc= "Http://gg.blueidea.com/2006/chinaok/468x60.gif"; Adbanners[4].href= "http://www.chinaok.net.cn"; Adbanners[4].imgwidth= "468"; adbanners[4].imgheight= "60"; adbanners[4].imgalt= "Build station, revision, promotion, find eurofilm power"; adbanners[4].weight=30; adbanners[4].place=5; adbanners[4].type=5; adbanners[4].id=56; Adbanners[5].imgsrc= "Http://gg.blueidea.com/2006/now/208x32.gif"; Adbanners[5].href= "http://www.now.cn"; Adbanners[5].imgwidth= "208"; Adbanners[5].imgheight= "32"; adbanners[5].imgalt= "Domain name free trial"; adbanners[5].weight=20; adbanners[5].place=4; adbanners[5].type=4; adbanners[5].id=41; Adbanners[6].htmlcode=' <script type= ' text/javascript ' >google_ad_client =  ' pub-5841412030047197 '; google_ad_width  = 728;google_ad_height = 90;google_alternate_ad_url =  "http://www.blueidea.com/ Js/google_adsense_script.html ";google_ad_format = " 728x90_as "; google_ad_channel =" 7977407778 "; google_ad_type =  "Text_image";google_color_border =  "6699CC";google_color_bg =  " 003366 ";google_color_link = " FFFFFF ";google_color_url = " Aecceb "google_color_text =";   "Aecceb" </script><script type= "Text/javascript"  src= "http://" Pagead2.googlesyndication.com/pagead/show_ads.js "></script><br><br>"; adbanners[6].weight=10; adbanners[6].place=1; adbanners[6].type=1; adbanners[6].id=29; Adbanners[7].htmlcode= ' <a href=http://blogbeta.blueidea.com target=_blank><b>blogbeta </b></a> <a href=http://www.idc2008.com target=_blank><b><font color=red> Xiamen Digital Engine delivers new three line space </font></b></a> <span id= "Bxna" >BXNA  tips </span><script type= "Text/javascript" >var vp = new  Flashobject ("http://blog.blueidea.com/bxna/styles/mxna/bxna.swf?clr= #484848 &dy=-2&showmode=1",  " DP ", " 169 ", ",  "7",  "#FFFFFF"); Vp.addparam ("wmode",  "Transparent");  vp.write ( "Bxna");</script> '; adbanners[7].weight=10; adbanners[7].place=7; adbanners[7].type=7; adbanners[7].id=50; Adbanners[8].htmlcode= ' <table border= "0"  align= "center"  cellpadding= "0"  cellspacing= "0"  height= " bgcolor=" and "#FFFFFF" ><tr><td><a href=http://www.blueidea.com/game/ site/2006dengfeng target=_blank><img src=http://gg.blueidea.com/2006/blueidea/d2.gif  Border=0></a></td><td width= "6" ></td><td><a href= "380.gif"   alt= "Kimshan ci PA logo solicitation Activities"   border= "0"  /></a></td></tr></table> "; adbanners[8].weight=10; adbanners[8].place=9; adbanners[8].type=6; adbanners[8].id=57;</textarea> <div id= "Divjsinputbar" > <input type= "button" value= "OK"/> <inpu T type= "button" value= "Cancel"/> </div></div><div id= "divjsoutput" ></div><div id= " Divwaiting "> Processing...<span id=" spnprocess "></span><br> <input type=" button "value=" Stop "/></div></body></html>

[Ctrl + A ALL SELECT hint: You can modify some of the code, and then run]







Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.