Skip to content

Instantly share code, notes, and snippets.

@xDimGG
Last active July 7, 2017 02:22
Show Gist options
  • Save xDimGG/5521345e395395e05e8ff741ab852718 to your computer and use it in GitHub Desktop.
Save xDimGG/5521345e395395e05e8ff741ab852718 to your computer and use it in GitHub Desktop.
(function() {
// Minified JS Beautifier : http://dpidudyah7i0b.cloudfront.net/codemirror/jsb/lib/beautify.js
function in_array(e,t){for(var n=0;n<t.length;n+=1)if(t[n]===e)return!0;return!1}function trim(e){return e.replace(/^\s+|\s+$/g,"")}function js_beautify(e,t){"use strict";return new Beautifier(e,t).beautify()}function Beautifier(e,t){"use strict";function n(e,t){var n=0;return e&&(n=e.indentation_level,!I.just_added_newline()&&e.line_indent_level>n&&(n=e.line_indent_level)),{mode:t,parent:e,last_text:e?e.last_text:"",last_word:e?e.last_word:"",declaration_statement:!1,declaration_assignment:!1,multiline_frame:!1,if_block:!1,else_block:!1,do_block:!1,do_while:!1,in_case_statement:!1,in_case:!1,case_body:!1,indentation_level:n,line_indent_level:e?e.line_indent_level:n,start_line_index:I.get_line_number(),ternary_depth:0}}function _(e){var t=e.newlines;if($.keep_array_indentation&&E(F.mode))for(n=0;n<t;n+=1)a(n>0);else if($.max_preserve_newlines&&t>$.max_preserve_newlines&&(t=$.max_preserve_newlines),$.preserve_newlines&&e.newlines>1){a();for(var n=1;n<t;n+=1)a(!0)}Z[(B=e).type]()}function r(e){for(var t=[],n=(e=e.replace(/\x0d/g,"")).indexOf("\n");-1!==n;)t.push(e.substring(0,n)),n=(e=e.substring(n+1)).indexOf("\n");return e.length&&t.push(e),t}function i(e){e=void 0!==e&&e,I.just_added_newline()||($.preserve_newlines&&B.wanted_newline||e?a(!1,!0):$.wrap_line_length&&I.current_line.get_character_count()+B.text.length+(I.space_before_token?1:0)>=$.wrap_line_length&&a(!1,!0))}function a(e,t){if(!t&&";"!==F.last_text&&","!==F.last_text&&"="!==F.last_text&&"TK_OPERATOR"!==W)for(;F.mode===MODE.Statement&&!F.if_block&&!F.do_block;)p();I.add_new_line(e)&&(F.multiline_frame=!0)}function o(){I.just_added_newline()&&($.keep_array_indentation&&E(F.mode)&&B.wanted_newline?(I.current_line.push(B.whitespace_before),I.space_before_token=!1):I.set_indent(F.indentation_level)&&(F.line_indent_level=F.indentation_level))}function s(e){e=e||B.text,o(),I.add_token(e)}function l(){F.indentation_level+=1}function c(){F.indentation_level>0&&(!F.parent||F.indentation_level>F.parent.indentation_level)&&(F.indentation_level-=1)}function d(e){F?(Q.push(F),U=F):U=n(null,e),F=n(U,e)}function E(e){return e===MODE.ArrayLiteral}function f(e){return in_array(e,[MODE.Expression,MODE.ForInitializer,MODE.Conditional])}function p(){Q.length>0&&(U=F,F=Q.pop(),U.mode===MODE.Statement&&I.remove_redundant_indentation(U))}function u(){return F.parent.mode===MODE.ObjectLiteral&&F.mode===MODE.Statement&&(":"===F.last_text&&0===F.ternary_depth||"TK_RESERVED"===W&&in_array(F.last_text,["get","set"]))}function T(){return!!("TK_RESERVED"===W&&in_array(F.last_text,["var","let","const"])&&"TK_WORD"===B.type||"TK_RESERVED"===W&&"do"===F.last_text||"TK_RESERVED"===W&&"return"===F.last_text&&!B.wanted_newline||"TK_RESERVED"===W&&"else"===F.last_text&&("TK_RESERVED"!==B.type||"if"!==B.text)||"TK_END_EXPR"===W&&(U.mode===MODE.ForInitializer||U.mode===MODE.Conditional)||"TK_WORD"===W&&F.mode===MODE.BlockStatement&&!F.in_case&&"--"!==B.text&&"++"!==B.text&&"TK_WORD"!==B.type&&"TK_RESERVED"!==B.type||F.mode===MODE.ObjectLiteral&&(":"===F.last_text&&0===F.ternary_depth||"TK_RESERVED"===W&&in_array(F.last_text,["get","set"])))&&(d(MODE.Statement),l(),"TK_RESERVED"===W&&in_array(F.last_text,["var","let","const"])&&"TK_WORD"===B.type&&(F.declaration_statement=!0),u()||i("TK_RESERVED"===B.type&&in_array(B.text,["do","for","if","while"])),!0)}function h(e,t){for(var n=0;n<e.length;n++)if(trim(e[n]).charAt(0)!==t)return!1;return!0}function R(e,t){for(var n,_=0,r=e.length;_<r;_++)if((n=e[_])&&0!==n.indexOf(t))return!1;return!0}function K(e){return in_array(e,["case","return","do","if","throw","else"])}function x(e){var t=P+(e||0);return t<0||t>=q.length?null:q[t]}function O(){T();var e=MODE.Expression;if("["===B.text){if("TK_WORD"===W||")"===F.last_text)return"TK_RESERVED"===W&&in_array(F.last_text,j.line_starters)&&(I.space_before_token=!0),d(e),s(),l(),void($.space_in_paren&&(I.space_before_token=!0));e=MODE.ArrayLiteral,E(F.mode)&&("["!==F.last_text&&(","!==F.last_text||"]"!==X&&"}"!==X)||$.keep_array_indentation||a())}else"TK_RESERVED"===W&&"for"===F.last_text?e=MODE.ForInitializer:"TK_RESERVED"===W&&in_array(F.last_text,["if","while"])&&(e=MODE.Conditional);";"===F.last_text||"TK_START_BLOCK"===W?a():"TK_END_EXPR"===W||"TK_START_EXPR"===W||"TK_END_BLOCK"===W||"."===F.last_text?i(B.wanted_newline):"TK_RESERVED"===W&&"("===B.text||"TK_WORD"===W||"TK_OPERATOR"===W?"TK_RESERVED"===W&&("function"===F.last_word||"typeof"===F.last_word)||"*"===F.last_text&&"function"===X?$.space_after_anon_function&&(I.space_before_token=!0):"TK_RESERVED"!==W||!in_array(F.last_text,j.line_starters)&&"catch"!==F.last_text||$.space_before_conditional&&(I.space_before_token=!0):I.space_before_token=!0,"("===B.text&&("TK_EQUALS"!==W&&"TK_OPERATOR"!==W||u()||i()),d(e),s(),$.space_in_paren&&(I.space_before_token=!0),l()}function y(){for(;F.mode===MODE.Statement;)p();F.multiline_frame&&i("]"===B.text&&E(F.mode)&&!$.keep_array_indentation),$.space_in_paren&&("TK_START_EXPR"!==W||$.space_in_empty_paren?I.space_before_token=!0:(I.trim(),I.space_before_token=!1)),"]"===B.text&&$.keep_array_indentation?(s(),p()):(p(),s()),I.remove_redundant_indentation(U),F.do_while&&U.mode===MODE.Conditional&&(U.mode=MODE.Expression,F.do_block=!1,F.do_while=!1)}function m(){var e=x(1),t=x(2);d(t&&(":"===t.text&&in_array(e.type,["TK_STRING","TK_WORD","TK_RESERVED"])||in_array(e.text,["get","set"])&&in_array(t.type,["TK_WORD","TK_RESERVED"]))?in_array(X,["class","interface"])?MODE.BlockStatement:MODE.ObjectLiteral:MODE.BlockStatement);var n=!e.comments_before.length&&"}"===e.text&&"function"===F.last_word&&"TK_END_EXPR"===W;"expand"===$.brace_style||"none"===$.brace_style&&B.wanted_newline?"TK_OPERATOR"!==W&&(n||"TK_EQUALS"===W||"TK_RESERVED"===W&&K(F.last_text)&&"else"!==F.last_text)?I.space_before_token=!0:a(!1,!0):"TK_OPERATOR"!==W&&"TK_START_EXPR"!==W?"TK_START_BLOCK"===W?a():I.space_before_token=!0:E(U.mode)&&","===F.last_text&&("}"===X?I.space_before_token=!0:a()),s(),l()}function b(){for(;F.mode===MODE.Statement;)p();var e="TK_START_BLOCK"===W;"expand"===$.brace_style?e||a():e||(E(F.mode)&&$.keep_array_indentation?($.keep_array_indentation=!1,a(),$.keep_array_indentation=!0):a()),p(),s()}function D(){if("TK_RESERVED"===B.type&&F.mode!==MODE.ObjectLiteral&&in_array(B.text,["set","get"])&&(B.type="TK_WORD"),"TK_RESERVED"===B.type&&F.mode===MODE.ObjectLiteral&&":"==x(1).text&&(B.type="TK_WORD"),T()||!B.wanted_newline||f(F.mode)||"TK_OPERATOR"===W&&"--"!==F.last_text&&"++"!==F.last_text||"TK_EQUALS"===W||!$.preserve_newlines&&"TK_RESERVED"===W&&in_array(F.last_text,["var","let","const","set","get"])||a(),F.do_block&&!F.do_while){if("TK_RESERVED"===B.type&&"while"===B.text)return I.space_before_token=!0,s(),I.space_before_token=!0,void(F.do_while=!0);a(),F.do_block=!1}if(F.if_block)if(F.else_block||"TK_RESERVED"!==B.type||"else"!==B.text){for(;F.mode===MODE.Statement;)p();F.if_block=!1,F.else_block=!1}else F.else_block=!0;return"TK_RESERVED"===B.type&&("case"===B.text||"default"===B.text&&F.in_case_statement)?(a(),(F.case_body||$.jslint_happy)&&(c(),F.case_body=!1),s(),F.in_case=!0,void(F.in_case_statement=!0)):("TK_RESERVED"===B.type&&"function"===B.text&&((in_array(F.last_text,["}",";"])||I.just_added_newline()&&!in_array(F.last_text,["[","{",":","=",","]))&&(I.just_added_blankline()||B.comments_before.length||(a(),a(!0))),"TK_RESERVED"===W||"TK_WORD"===W?"TK_RESERVED"===W&&in_array(F.last_text,["get","set","new","return","export"])?I.space_before_token=!0:"TK_RESERVED"===W&&"default"===F.last_text&&"export"===X?I.space_before_token=!0:a():"TK_OPERATOR"===W||"="===F.last_text?I.space_before_token=!0:(F.multiline_frame||!f(F.mode)&&!E(F.mode))&&a()),"TK_COMMA"!==W&&"TK_START_EXPR"!==W&&"TK_EQUALS"!==W&&"TK_OPERATOR"!==W||u()||i(),"TK_RESERVED"===B.type&&in_array(B.text,["function","get","set"])?(s(),void(F.last_word=B.text)):(G="NONE","TK_END_BLOCK"===W?"TK_RESERVED"===B.type&&in_array(B.text,["else","catch","finally"])?"expand"===$.brace_style||"end-expand"===$.brace_style||"none"===$.brace_style&&B.wanted_newline?G="NEWLINE":(G="SPACE",I.space_before_token=!0):G="NEWLINE":"TK_SEMICOLON"===W&&F.mode===MODE.BlockStatement?G="NEWLINE":"TK_SEMICOLON"===W&&f(F.mode)?G="SPACE":"TK_STRING"===W?G="NEWLINE":"TK_RESERVED"===W||"TK_WORD"===W||"*"===F.last_text&&"function"===X?G="SPACE":"TK_START_BLOCK"===W?G="NEWLINE":"TK_END_EXPR"===W&&(I.space_before_token=!0,G="NEWLINE"),"TK_RESERVED"===B.type&&in_array(B.text,j.line_starters)&&")"!==F.last_text&&(G="else"===F.last_text||"export"===F.last_text?"SPACE":"NEWLINE"),"TK_RESERVED"===B.type&&in_array(B.text,["else","catch","finally"])?"TK_END_BLOCK"!==W||"expand"===$.brace_style||"end-expand"===$.brace_style||"none"===$.brace_style&&B.wanted_newline?a():(I.trim(!0),"}"!==I.current_line.last()&&a(),I.space_before_token=!0):"NEWLINE"===G?"TK_RESERVED"===W&&K(F.last_text)?I.space_before_token=!0:"TK_END_EXPR"!==W?"TK_START_EXPR"===W&&"TK_RESERVED"===B.type&&in_array(B.text,["var","let","const"])||":"===F.last_text||("TK_RESERVED"===B.type&&"if"===B.text&&"else"===F.last_text?I.space_before_token=!0:a()):"TK_RESERVED"===B.type&&in_array(B.text,j.line_starters)&&")"!==F.last_text&&a():F.multiline_frame&&E(F.mode)&&","===F.last_text&&"}"===X?a():"SPACE"===G&&(I.space_before_token=!0),s(),F.last_word=B.text,"TK_RESERVED"===B.type&&"do"===B.text&&(F.do_block=!0),void("TK_RESERVED"===B.type&&"if"===B.text&&(F.if_block=!0))))}function A(){for(T()&&(I.space_before_token=!1);F.mode===MODE.Statement&&!F.if_block&&!F.do_block;)p();s()}function S(){T()?I.space_before_token=!0:"TK_RESERVED"===W||"TK_WORD"===W?I.space_before_token=!0:"TK_COMMA"===W||"TK_START_EXPR"===W||"TK_EQUALS"===W||"TK_OPERATOR"===W?u()||i():a(),s()}function w(){T(),F.declaration_statement&&(F.declaration_assignment=!0),I.space_before_token=!0,s(),I.space_before_token=!0}function v(){if(F.declaration_statement)return f(F.parent.mode)&&(F.declaration_assignment=!1),s(),void(F.declaration_assignment?(F.declaration_assignment=!1,a(!1,!0)):I.space_before_token=!0);s(),F.mode===MODE.ObjectLiteral||F.mode===MODE.Statement&&F.parent.mode===MODE.ObjectLiteral?(F.mode===MODE.Statement&&p(),a()):I.space_before_token=!0}function k(){if(T(),"TK_RESERVED"===W&&K(F.last_text))return I.space_before_token=!0,void s();if("*"!==B.text||"TK_DOT"!==W){if(":"===B.text&&F.in_case)return F.case_body=!0,l(),s(),a(),void(F.in_case=!1);if("::"!==B.text){!B.wanted_newline||"--"!==B.text&&"++"!==B.text||a(!1,!0),"TK_OPERATOR"===W&&i();var e=!0,t=!0;in_array(B.text,["--","++","!","~"])||in_array(B.text,["-","+"])&&(in_array(W,["TK_START_BLOCK","TK_START_EXPR","TK_EQUALS","TK_OPERATOR"])||in_array(F.last_text,j.line_starters)||","===F.last_text)?(e=!1,t=!1,";"===F.last_text&&f(F.mode)&&(e=!0),"TK_RESERVED"===W||"TK_END_EXPR"===W?e=!0:"TK_OPERATOR"===W&&(e=in_array(B.text,["--","-"])&&in_array(F.last_text,["--","-"])||in_array(B.text,["++","+"])&&in_array(F.last_text,["++","+"])),F.mode!==MODE.BlockStatement&&F.mode!==MODE.Statement||"{"!==F.last_text&&";"!==F.last_text||a()):":"===B.text?0===F.ternary_depth?e=!1:F.ternary_depth-=1:"?"===B.text?F.ternary_depth+=1:"*"===B.text&&"TK_RESERVED"===W&&"function"===F.last_text&&(e=!1,t=!1),I.space_before_token=I.space_before_token||e,s(),I.space_before_token=t}else s()}else s()}function g(){var e,t=r(B.text),n=!1,_=!1,i=B.whitespace_before,o=i.length;for(a(!1,!0),t.length>1&&(h(t.slice(1),"*")?n=!0:R(t.slice(1),i)&&(_=!0)),s(t[0]),e=1;e<t.length;e++)a(!1,!0),n?s(" "+trim(t[e])):_&&t[e].length>o?s(t[e].substring(o)):I.add_token(t[e]);a(!1,!0)}function M(){I.space_before_token=!0,s(),I.space_before_token=!0}function N(){B.wanted_newline?a(!1,!0):I.trim(!0),I.space_before_token=!0,s(),a(!1,!0)}function C(){T(),"TK_RESERVED"===W&&K(F.last_text)?I.space_before_token=!0:i(")"===F.last_text&&$.break_chained_methods),s()}function L(){s(),"\n"===B.text[B.text.length-1]&&a()}function V(){for(;F.mode===MODE.Statement;)p()}var I,P,j,B,W,X,z,F,U,Q,G,Z,$,q=[],H="";for(Z={TK_START_EXPR:O,TK_END_EXPR:y,TK_START_BLOCK:m,TK_END_BLOCK:b,TK_WORD:D,TK_RESERVED:D,TK_SEMICOLON:A,TK_STRING:S,TK_EQUALS:w,TK_OPERATOR:k,TK_COMMA:v,TK_BLOCK_COMMENT:g,TK_INLINE_COMMENT:M,TK_COMMENT:N,TK_DOT:C,TK_UNKNOWN:L,TK_EOF:V},$={},void 0!==(t=t||{}).braces_on_own_line&&($.brace_style=t.braces_on_own_line?"expand":"collapse"),$.brace_style=t.brace_style?t.brace_style:$.brace_style?$.brace_style:"collapse","expand-strict"===$.brace_style&&($.brace_style="expand"),$.indent_size=t.indent_size?parseInt(t.indent_size,10):4,$.indent_char=t.indent_char?t.indent_char:" ",$.preserve_newlines=void 0===t.preserve_newlines||t.preserve_newlines,$.break_chained_methods=void 0!==t.break_chained_methods&&t.break_chained_methods,$.max_preserve_newlines=void 0===t.max_preserve_newlines?0:parseInt(t.max_preserve_newlines,10),$.space_in_paren=void 0!==t.space_in_paren&&t.space_in_paren,$.space_in_empty_paren=void 0!==t.space_in_empty_paren&&t.space_in_empty_paren,$.jslint_happy=void 0!==t.jslint_happy&&t.jslint_happy,$.space_after_anon_function=void 0!==t.space_after_anon_function&&t.space_after_anon_function,$.keep_array_indentation=void 0!==t.keep_array_indentation&&t.keep_array_indentation,$.space_before_conditional=void 0===t.space_before_conditional||t.space_before_conditional,$.unescape_strings=void 0!==t.unescape_strings&&t.unescape_strings,$.wrap_line_length=void 0===t.wrap_line_length?0:parseInt(t.wrap_line_length,10),$.e4x=void 0!==t.e4x&&t.e4x,$.end_with_newline=void 0!==t.end_with_newline&&t.end_with_newline,$.jslint_happy&&($.space_after_anon_function=!0),t.indent_with_tabs&&($.indent_char="\t",$.indent_size=1),z="";$.indent_size>0;)z+=$.indent_char,$.indent_size-=1;var J=0;if(e&&e.length){for(;" "===e.charAt(J)||"\t"===e.charAt(J);)H+=e.charAt(J),J+=1;e=e.substring(J)}W="TK_START_BLOCK",X="",I=new Output(z,H),Q=[],d(MODE.BlockStatement),this.beautify=function(){var t,n;for(j=new tokenizer(e,$,z),q=j.tokenize(),P=0;t=x();){for(var r=0;r<t.comments_before.length;r++)_(t.comments_before[r]);_(t),X=F.last_text,W=t.type,F.last_text=t.text,P+=1}return n=I.get_code(),$.end_with_newline&&(n+="\n"),n}}function OutputLine(e){var t=0,n=-1,_=[],r=!0;this.set_indent=function(_){t=e.baseIndentLength+_*e.indent_length,n=_},this.get_character_count=function(){return t},this.is_empty=function(){return r},this.last=function(){return this._empty?null:_[_.length-1]},this.push=function(e){_.push(e),t+=e.length,r=!1},this.remove_indent=function(){n>0&&(n-=1,t-=e.indent_length)},this.trim=function(){for(;" "===this.last();){_.pop();t-=1}r=0===_.length},this.toString=function(){var t="";return this._empty||(n>=0&&(t=e.indent_cache[n]),t+=_.join("")),t}}function Output(e,t){t=t||"",this.indent_cache=[t],this.baseIndentLength=t.length,this.indent_length=e.length;var n=[];this.baseIndentString=t,this.indent_string=e,this.current_line=null,this.space_before_token=!1,this.get_line_number=function(){return n.length},this.add_new_line=function(e){return(1!==this.get_line_number()||!this.just_added_newline())&&(!(!e&&this.just_added_newline())&&(this.current_line=new OutputLine(this),n.push(this.current_line),!0))},this.add_new_line(!0),this.get_code=function(){return n.join("\n").replace(/[\r\n\t ]+$/,"")},this.set_indent=function(e){if(n.length>1){for(;e>=this.indent_cache.length;)this.indent_cache.push(this.indent_cache[this.indent_cache.length-1]+this.indent_string);return this.current_line.set_indent(e),!0}return this.current_line.set_indent(0),!1},this.add_token=function(e){this.add_space_before_token(),this.current_line.push(e)},this.add_space_before_token=function(){this.space_before_token&&!this.just_added_newline()&&this.current_line.push(" "),this.space_before_token=!1},this.remove_redundant_indentation=function(e){if(!e.multiline_frame&&e.mode!==MODE.ForInitializer&&e.mode!==MODE.Conditional)for(var t=e.start_line_index,_=n.length;t<_;)n[t].remove_indent(),t++},this.trim=function(_){for(_=void 0!==_&&_,this.current_line.trim(e,t);_&&n.length>1&&this.current_line.is_empty();)n.pop(),this.current_line=n[n.length-1],this.current_line.trim()},this.just_added_newline=function(){return this.current_line.is_empty()},this.just_added_blankline=function(){return!!this.just_added_newline()&&(1===n.length||n[n.length-2].is_empty())}}function tokenizer(e,t,n){function _(){var _,u=[];if(s=0,l="",E>=f)return["","TK_EOF"];var T;T=d.length?d[d.length-1]:new Token("TK_START_BLOCK","{");var h=e.charAt(E);for(E+=1;in_array(h,i);){if("\n"===h?(s+=1,u=[]):s&&(h===n?u.push(n):"\r"!==h&&u.push(" ")),E>=f)return["","TK_EOF"];h=e.charAt(E),E+=1}if(u.length&&(l=u.join("")),a.test(h)){var R=!0,K=!0,x=a;for("0"===h&&E<f&&/[Xx]/.test(e.charAt(E))?(R=!1,K=!1,h+=e.charAt(E),E+=1,x=/[0123456789abcdefABCDEF]/):(h="",E-=1);E<f&&x.test(e.charAt(E));)h+=e.charAt(E),E+=1,R&&E<f&&"."===e.charAt(E)&&(h+=e.charAt(E),E+=1,R=!1),K&&E<f&&/[Ee]/.test(e.charAt(E))&&(h+=e.charAt(E),(E+=1)<f&&/[+-]/.test(e.charAt(E))&&(h+=e.charAt(E),E+=1),K=!1,R=!1);return[h,"TK_WORD"]}if(acorn.isIdentifierStart(e.charCodeAt(E-1))){if(E<f)for(;acorn.isIdentifierChar(e.charCodeAt(E))&&(h+=e.charAt(E),(E+=1)!==f););return"TK_DOT"===T.type||"TK_RESERVED"===T.type&&in_array(T.text,["set","get"])||!in_array(h,p)?[h,"TK_WORD"]:"in"===h?[h,"TK_OPERATOR"]:[h,"TK_RESERVED"]}if("("===h||"["===h)return[h,"TK_START_EXPR"];if(")"===h||"]"===h)return[h,"TK_END_EXPR"];if("{"===h)return[h,"TK_START_BLOCK"];if("}"===h)return[h,"TK_END_BLOCK"];if(";"===h)return[h,"TK_SEMICOLON"];if("/"===h){var O="",y=!0;if("*"===e.charAt(E)){if((E+=1)<f)for(;E<f&&("*"!==e.charAt(E)||!e.charAt(E+1)||"/"!==e.charAt(E+1))&&(h=e.charAt(E),O+=h,"\n"!==h&&"\r"!==h||(y=!1),!((E+=1)>=f)););return E+=2,y&&0===s?["/*"+O+"*/","TK_INLINE_COMMENT"]:["/*"+O+"*/","TK_BLOCK_COMMENT"]}if("/"===e.charAt(E)){for(O=h;"\r"!==e.charAt(E)&&"\n"!==e.charAt(E)&&(O+=e.charAt(E),!((E+=1)>=f)););return[O,"TK_COMMENT"]}}if("`"===h||"'"===h||'"'===h||("/"===h||t.e4x&&"<"===h&&e.slice(E-1).match(/^<([-a-zA-Z:0-9_.]+|{[^{}]*}|!\[CDATA\[[\s\S]*?\]\])\s*([-a-zA-Z:0-9_.]+=('[^']*'|"[^"]*"|{[^{}]*})\s*)*\/?\s*>/))&&("TK_RESERVED"===T.type&&in_array(T.text,["return","case","throw","else","do","typeof","yield"])||"TK_END_EXPR"===T.type&&")"===T.text&&T.parent&&"TK_RESERVED"===T.parent.type&&in_array(T.parent.text,["if","while","for"])||in_array(T.type,["TK_COMMENT","TK_START_EXPR","TK_START_BLOCK","TK_END_BLOCK","TK_OPERATOR","TK_EQUALS","TK_EOF","TK_SEMICOLON","TK_COMMA"]))){var m=h,b=!1,D=!1;if(_=h,"/"===m)for(var A=!1;E<f&&(b||A||e.charAt(E)!==m)&&!acorn.newline.test(e.charAt(E));)_+=e.charAt(E),b?b=!1:(b="\\"===e.charAt(E),"["===e.charAt(E)?A=!0:"]"===e.charAt(E)&&(A=!1)),E+=1;else if(t.e4x&&"<"===m){var S=/<(\/?)([-a-zA-Z:0-9_.]+|{[^{}]*}|!\[CDATA\[[\s\S]*?\]\])\s*([-a-zA-Z:0-9_.]+=('[^']*'|"[^"]*"|{[^{}]*})\s*)*(\/?)\s*>/g,w=e.slice(E-1),v=S.exec(w);if(v&&0===v.index){for(var k=v[2],g=0;v;){var M=!!v[1],N=v[2],C=!!v[v.length-1]||"![CDATA["===N.slice(0,8);if(N!==k||C||(M?--g:++g),g<=0)break;v=S.exec(w)}var L=v?v.index+v[0].length:w.length;return E+=L-1,[w.slice(0,L),"TK_STRING"]}}else for(;E<f&&(b||e.charAt(E)!==m&&("`"===m||!acorn.newline.test(e.charAt(E))));)_+=e.charAt(E),b?("x"!==e.charAt(E)&&"u"!==e.charAt(E)||(D=!0),b=!1):b="\\"===e.charAt(E),E+=1;if(D&&t.unescape_strings&&(_=r(_)),E<f&&e.charAt(E)===m&&(_+=m,E+=1,"/"===m))for(;E<f&&acorn.isIdentifierStart(e.charCodeAt(E));)_+=e.charAt(E),E+=1;return[_,"TK_STRING"]}if("#"===h){if(0===d.length&&"!"===e.charAt(E)){for(_=h;E<f&&"\n"!==h;)_+=h=e.charAt(E),E+=1;return[trim(_)+"\n","TK_UNKNOWN"]}var V="#";if(E<f&&a.test(e.charAt(E))){do{V+=h=e.charAt(E),E+=1}while(E<f&&"#"!==h&&"="!==h);return"#"===h||("["===e.charAt(E)&&"]"===e.charAt(E+1)?(V+="[]",E+=2):"{"===e.charAt(E)&&"}"===e.charAt(E+1)&&(V+="{}",E+=2)),[V,"TK_WORD"]}}if("<"===h&&"\x3c!--"===e.substring(E-1,E+3)){for(E+=3,h="\x3c!--";"\n"!==e.charAt(E)&&E<f;)h+=e.charAt(E),E++;return c=!0,[h,"TK_COMMENT"]}if("-"===h&&c&&"--\x3e"===e.substring(E-1,E+2))return c=!1,E+=2,["--\x3e","TK_COMMENT"];if("."===h)return[h,"TK_DOT"];if(in_array(h,o)){for(;E<f&&in_array(h+e.charAt(E),o)&&(h+=e.charAt(E),!((E+=1)>=f)););return","===h?[h,"TK_COMMA"]:"="===h?[h,"TK_EQUALS"]:[h,"TK_OPERATOR"]}return[h,"TK_UNKNOWN"]}function r(e){for(var t,n=!1,_="",r=0,i="",a=0;n||r<e.length;)if(t=e.charAt(r),r++,n){if(n=!1,"x"===t)i=e.substr(r,2),r+=2;else{if("u"!==t){_+="\\"+t;continue}i=e.substr(r,4),r+=4}if(!i.match(/^[0123456789abcdefABCDEF]+$/))return e;if((a=parseInt(i,16))>=0&&a<32){_+="x"===t?"\\x"+i:"\\u"+i;continue}if(34===a||39===a||92===a)_+="\\"+String.fromCharCode(a);else{if("x"===t&&a>126&&a<=255)return e;_+=String.fromCharCode(a)}}else"\\"===t?n=!0:_+=t;return _}var i="\n\r\t ".split(""),a=/[0-9]/,o="+ - * / % & ++ -- = += -= *= /= %= == === != !== > < >= <= >> << >>> >>>= >>= <<= && &= | || ! ~ , : ? ^ ^= |= :: => <%= <% %> <?= <? ?>".split(" ");this.line_starters="continue,try,throw,return,var,let,const,if,switch,case,default,for,while,break,function,yield,import,export".split(",");var s,l,c,d,E,f,p=this.line_starters.concat(["do","in","else","get","set","new","catch","finally","typeof"]);this.tokenize=function(){f=e.length,E=0,c=!1,d=[];for(var t,n,r,i=null,a=[],o=[];!n||"TK_EOF"!==n.type;){for(r=_(),t=new Token(r[1],r[0],s,l);"TK_INLINE_COMMENT"===t.type||"TK_COMMENT"===t.type||"TK_BLOCK_COMMENT"===t.type||"TK_UNKNOWN"===t.type;)o.push(t),r=_(),t=new Token(r[1],r[0],s,l);o.length&&(t.comments_before=o,o=[]),"TK_START_BLOCK"===t.type||"TK_START_EXPR"===t.type?(t.parent=n,i=t,a.push(t)):("TK_END_BLOCK"===t.type||"TK_END_EXPR"===t.type)&&i&&("]"===t.text&&"["===i.text||")"===t.text&&"("===i.text||"}"===t.text&&"}"===i.text)&&(t.parent=i.parent,i=a.pop()),d.push(t),n=t}return d}}var acorn={};!function(e){var t="ªµºÀ-ÖØ-öø-ˁˆ-ˑˠ-ˤˬˮͰ-ʹͶͷͺ-ͽΆΈ-ΊΌΎ-ΡΣ-ϵϷ-ҁҊ-ԧԱ-Ֆՙա-ևא-תװ-ײؠ-يٮٯٱ-ۓەۥۦۮۯۺ-ۼۿܐܒ-ܯݍ-ޥޱߊ-ߪߴߵߺࠀ-ࠕࠚࠤࠨࡀ-ࡘࢠࢢ-ࢬऄ-हऽॐक़-ॡॱ-ॷॹ-ॿঅ-ঌএঐও-নপ-রলশ-হঽৎড়ঢ়য়-ৡৰৱਅ-ਊਏਐਓ-ਨਪ-ਰਲਲ਼ਵਸ਼ਸਹਖ਼-ੜਫ਼ੲ-ੴઅ-ઍએ-ઑઓ-નપ-રલળવ-હઽૐૠૡଅ-ଌଏଐଓ-ନପ-ରଲଳଵ-ହଽଡ଼ଢ଼ୟ-ୡୱஃஅ-ஊஎ-ஐஒ-கஙசஜஞடணதந-பம-ஹௐఅ-ఌఎ-ఐఒ-నప-ళవ-హఽౘౙౠౡಅ-ಌಎ-ಐಒ-ನಪ-ಳವ-ಹಽೞೠೡೱೲഅ-ഌഎ-ഐഒ-ഺഽൎൠൡൺ-ൿඅ-ඖක-නඳ-රලව-ෆก-ะาำเ-ๆກຂຄງຈຊຍດ-ທນ-ຟມ-ຣລວສຫອ-ະາຳຽເ-ໄໆໜ-ໟༀཀ-ཇཉ-ཬྈ-ྌက-ဪဿၐ-ၕၚ-ၝၡၥၦၮ-ၰၵ-ႁႎႠ-ჅჇჍა-ჺჼ-ቈቊ-ቍቐ-ቖቘቚ-ቝበ-ኈኊ-ኍነ-ኰኲ-ኵኸ-ኾዀዂ-ዅወ-ዖዘ-ጐጒ-ጕጘ-ፚᎀ-ᎏᎠ-Ᏼᐁ-ᙬᙯ-ᙿᚁ-ᚚᚠ-ᛪᛮ-ᛰᜀ-ᜌᜎ-ᜑᜠ-ᜱᝀ-ᝑᝠ-ᝬᝮ-ᝰក-ឳៗៜᠠ-ᡷᢀ-ᢨᢪᢰ-ᣵᤀ-ᤜᥐ-ᥭᥰ-ᥴᦀ-ᦫᧁ-ᧇᨀ-ᨖᨠ-ᩔᪧᬅ-ᬳᭅ-ᭋᮃ-ᮠᮮᮯᮺ-ᯥᰀ-ᰣᱍ-ᱏᱚ-ᱽᳩ-ᳬᳮ-ᳱᳵᳶᴀ-ᶿḀ-ἕἘ-Ἕἠ-ὅὈ-Ὅὐ-ὗὙὛὝὟ-ώᾀ-ᾴᾶ-ᾼιῂ-ῄῆ-ῌῐ-ΐῖ-Ίῠ-Ῥῲ-ῴῶ-ῼⁱⁿₐ-ₜℂℇℊ-ℓℕℙ-ℝℤΩℨK-ℭℯ-ℹℼ-ℿⅅ-ⅉⅎⅠ-ↈⰀ-Ⱞⰰ-ⱞⱠ-ⳤⳫ-ⳮⳲⳳⴀ-ⴥⴧⴭⴰ-ⵧⵯⶀ-ⶖⶠ-ⶦⶨ-ⶮⶰ-ⶶⶸ-ⶾⷀ-ⷆⷈ-ⷎⷐ-ⷖⷘ-ⷞⸯ々-〇〡-〩〱-〵〸-〼ぁ-ゖゝ-ゟァ-ヺー-ヿㄅ-ㄭㄱ-ㆎㆠ-ㆺㇰ-ㇿ㐀-䶵一-鿌ꀀ-ꒌꓐ-ꓽꔀ-ꘌꘐ-ꘟꘪꘫꙀ-ꙮꙿ-ꚗꚠ-ꛯꜗ-ꜟꜢ-ꞈꞋ-ꞎꞐ-ꞓꞠ-Ɦꟸ-ꠁꠃ-ꠅꠇ-ꠊꠌ-ꠢꡀ-ꡳꢂ-ꢳꣲ-ꣷꣻꤊ-ꤥꤰ-ꥆꥠ-ꥼꦄ-ꦲꧏꨀ-ꨨꩀ-ꩂꩄ-ꩋꩠ-ꩶꩺꪀ-ꪯꪱꪵꪶꪹ-ꪽꫀꫂꫛ-ꫝꫠ-ꫪꫲ-ꫴꬁ-ꬆꬉ-ꬎꬑ-ꬖꬠ-ꬦꬨ-ꬮꯀ-ꯢ가-힣ힰ-ퟆퟋ-ퟻ豈-舘並-龎ff-stﬓ-ﬗיִײַ-ﬨשׁ-זּטּ-לּמּנּסּףּפּצּ-ﮱﯓ-ﴽﵐ-ﶏﶒ-ﷇﷰ-ﷻﹰ-ﹴﹶ-ﻼA-Za-zヲ-하-ᅦᅧ-ᅬᅭ-ᅲᅳ-ᅵ",n=new RegExp("["+t+"]"),_=new RegExp("["+t+"̀-ͯ҃-֑҇-ׇֽֿׁׂׅׄؐ-ؚؠ-ىٲ-ۓۧ-ۨۻ-ۼܰ-݊ࠀ-ࠔࠛ-ࠣࠥ-ࠧࠩ-࠭ࡀ-ࡗࣤ-ࣾऀ-ःऺ-़ा-ॏ॑-ॗॢ-ॣ०-९ঁ-ঃ়া-ৄেৈৗয়-ৠਁ-ਃ਼ਾ-ੂੇੈੋ-੍ੑ੦-ੱੵઁ-ઃ઼ા-ૅે-ૉો-્ૢ-ૣ૦-૯ଁ-ଃ଼ା-ୄେୈୋ-୍ୖୗୟ-ୠ୦-୯ஂா-ூெ-ைொ-்ௗ௦-௯ఁ-ఃె-ైొ-్ౕౖౢ-ౣ౦-౯ಂಃ಼ಾ-ೄೆ-ೈೊ-್ೕೖೢ-ೣ೦-೯ംഃെ-ൈൗൢ-ൣ൦-൯ංඃ්ා-ුූෘ-ෟෲෳิ-ฺเ-ๅ๐-๙ິ-ູ່-ໍ໐-໙༘༙༠-༩༹༵༷ཁ-ཇཱ-྄྆-྇ྍ-ྗྙ-ྼ࿆က-ဩ၀-၉ၧ-ၭၱ-ၴႂ-ႍႏ-ႝ፝-፟ᜎ-ᜐᜠ-ᜰᝀ-ᝐᝲᝳក-ឲ៝០-៩᠋-᠍᠐-᠙ᤠ-ᤫᤰ-᤻ᥑ-ᥭᦰ-ᧀᧈ-ᧉ᧐-᧙ᨀ-ᨕᨠ-ᩓ᩠-᩿᩼-᪉᪐-᪙ᭆ-ᭋ᭐-᭙᭫-᭳᮰-᮹᯦-᯳ᰀ-ᰢ᱀-᱉ᱛ-ᱽ᳐-᳒ᴀ-ᶾḁ-ἕ‌‍‿⁀⁔⃐-⃥⃜⃡-⃰ⶁ-ⶖⷠ-ⷿ〡-〨゙゚Ꙁ-ꙭꙴ-꙽ꚟ꛰-꛱ꟸ-ꠀ꠆ꠋꠣ-ꠧꢀ-ꢁꢴ-꣄꣐-꣙ꣳ-ꣷ꤀-꤉ꤦ-꤭ꤰ-ꥅꦀ-ꦃ꦳-꧀ꨀ-ꨧꩀ-ꩁꩌ-ꩍ꩐-꩙ꩻꫠ-ꫩꫲ-ꫳꯀ-ꯡ꯬꯭꯰-꯹ﬠ-ﬨ︀-️︠-︦︳︴﹍-﹏0-9_]");e.newline=/[\n\r\u2028\u2029]/,e.isIdentifierStart=function(e){return e<65?36===e:e<91||(e<97?95===e:e<123||e>=170&&n.test(String.fromCharCode(e)))},e.isIdentifierChar=function(e){return e<48?36===e:e<58||!(e<65)&&(e<91||(e<97?95===e:e<123||e>=170&&_.test(String.fromCharCode(e))))}}(acorn);var MODE={BlockStatement:"BlockStatement",Statement:"Statement",ObjectLiteral:"ObjectLiteral",ArrayLiteral:"ArrayLiteral",ForInitializer:"ForInitializer",Conditional:"Conditional",Expression:"Expression"},Token=function(e,t,n,_,r,i){this.type=e,this.text=t,this.comments_before=[],this.newlines=n||0,this.wanted_newline=n>0,this.whitespace_before=_||"",this.parent=null};"function"==typeof define&&define.amd?define([],function(){return{js_beautify:js_beautify}}):"undefined"!=typeof exports?exports.js_beautify=js_beautify:"undefined"!=typeof window?window.js_beautify=js_beautify:"undefined"!=typeof global&&(global.js_beautify=js_beautify);
var s = document.getElementsByTagName('script'),
sa = [],
ra = [],
i;
for (i = 0; i < s.length; i++) {
if (s[i].src === '') {
ra.push(s[i].innerHTML);
} else {
sa.push(s[i].src);
}
}
with(window.open()) {
document.write('<textarea id="js" style="width:400px;height:200px"></textarea>');
for (i = 0; i < sa.length; i++) {
document.getElementById('js').value += sa[i] + '\n';
}
for (i = 0; i < ra.length; i++) {
document.getElementById('js').value += '\n-------\n\n' + js_beautify(ra[i]) + '\n';
}
}
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment