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

'; + out += ' '+uiButton('javascript:indentScript()', 'Indent'); + out += ' '+uiButton('javascript:toggleScriptOutput()', 'Output'); + out += '

'; + out += ''; c.innerHTML = out; } diff --git a/shlr/www/m/r2.js b/shlr/www/m/r2.js index 849cd0fe7e..54eb025a03 100644 --- a/shlr/www/m/r2.js +++ b/shlr/www/m/r2.js @@ -366,7 +366,7 @@ function _internal_cmd(c, cb) { } if (hascmd) { // TODO: use setTimeout for async? - if (typeof (r2plugin) != "undefined") { + if (typeof (r2plugin) != 'undefined') { // duktape cb (r2cmd(c)); } else { @@ -398,7 +398,7 @@ r2.cmd = function(c, cb) { cb (res); }); } else { - _internal_cmd (c, cb); + return _internal_cmd (c, cb); } } diff --git a/shlr/www/m/styles.css b/shlr/www/m/styles.css index 0ca7179cd3..e7f9256f14 100644 --- a/shlr/www/m/styles.css +++ b/shlr/www/m/styles.css @@ -259,3 +259,14 @@ input { td { text-align:left !important; } + +.output { + border: 1px solid red; + margin-left: 16px; + margin-top: 16px; + margin-bottom: 16px; + background-color: white; + font-family: Console, Courier New, monospace; + white-space: pre; + display: inline-block; +}