forked from astoilkov/console-powers
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconsole.message.min.js
More file actions
1 lines (1 loc) · 4.13 KB
/
Copy pathconsole.message.min.js
File metadata and controls
1 lines (1 loc) · 4.13 KB
1
!function(){function t(){return t.prototype.isPrototypeOf(this)?(this._rootSpan={styles:{},children:[],parent:null},this._currentSpan=this._rootSpan,this._waiting=0,void(this._readyCallback=null)):new t}function e(t,e){for(var n in e)void 0===t[n]&&(t[n]=e[n]);return t}var n={columnCount:!0,fillOpacity:!0,flexGrow:!0,flexShrink:!0,fontWeight:!0,lineHeight:!0,opacity:!0,order:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},r=function(){function t(t){t=t.toLowerCase();var e=/(chrome)[ \/]([\w.]+)/.exec(t)||/(webkit)[ \/]([\w.]+)/.exec(t)||/(opera)(?:.*version|)[ \/]([\w.]+)/.exec(t)||/(msie) ([\w.]+)/.exec(t)||t.indexOf("compatible")<0&&/(mozilla)(?:.*? rv:([\w.]+)|)/.exec(t)||[];return{browser:e[1]||"",version:e[2]||"0"}}var e=t(navigator.userAgent);return{isIE:"msie"==e.browser||"mozilla"==e.browser&&11==parseInt(e.version,10)}}();t.prototype={group:function(t){return this._currentSpan.children.push({type:t===!1?"groupCollapsed":"group",parent:this._currentSpan}),this},groupEnd:function(){return this._currentSpan.children.push({type:"groupEnd",parent:this._currentSpan}),this},span:function(t){var n={type:"span",styles:e(t||{},this._currentSpan.styles),children:[],parent:this._currentSpan};return this._currentSpan.children.push(n),this._currentSpan=n,this},spanEnd:function(){return this._currentSpan=this._currentSpan.parent||this._currentSpan,this},text:function(t,e){return this.span(e),this._currentSpan.children.push({type:"text",message:t,parent:this._currentSpan}),this.spanEnd()},line:function(t){return this._currentSpan.children.push({type:t||"log",parent:this._currentSpan}),this},image:function(t,n){var r=this,s=new Image,i=1;return n=e({backgroundImage:"url("+t+")",backgroundRepeat:"no-repeat",color:"transparent",fontSize:1},n),null!=n.zoom&&(i=parseFloat(n.zoom)||i),this.text(" ",n),this._wait(),s.onload=function(){var t=this.width*i,e=this.height*i;n.backgroundSize=t+"px "+(e+"px"),n.padding=e/2+"px "+t/2+"px",n.lineHeight=e,r._ready()},s.onerror=function(){r._ready()},s.src=t,this},element:function(t){return this._currentSpan.children.push({type:"element",element:t,parent:this._currentSpan}),this},object:function(t){return this._currentSpan.children.push({type:"object",object:t,parent:this._currentSpan}),this},print:function(){return"undefined"!=typeof console&&this._onReady(this._print),new t},_print:function(){var t,e=[this._newMessage()];this._printSpan(this._rootSpan,e);for(var n=0;n<e.length;n++)t=e[n],t.text&&"%c"!=t.text&&console[t.type]&&this._printMessage(t)},_printMessage:function(t){Function.prototype.apply.call(console[t.type],console,[t.text].concat(t.args))},_onReady:function(t){this._readyCallback=t,0===this._waiting&&this._ready()},_wait:function(){this._waiting+=1},_ready:function(){this._waiting-=1,this._waiting>0||(this._waiting=0,this._readyCallback())},_printSpan:function(t,e){var n=t.children,r=e[e.length-1];this._addSpanData(t,r);for(var s=0;s<n.length;s++)this._handleChild(n[s],e)},_handleChild:function(t,e){var n=e[e.length-1];switch(t.type){case"group":e.push(this._newMessage("group"));break;case"groupCollapsed":e.push(this._newMessage("groupCollapsed"));break;case"groupEnd":n=this._newMessage("groupEnd"),n.text=" ",e.push(n),e.push(this._newMessage());break;case"span":this._printSpan(t,e),this._addSpanData(t,n),this._addSpanData(t.parent,n);break;case"text":n.text+=t.message;break;case"element":n.text+="%o",n.args.push(t.element);break;case"object":n.text+="%O",n.args.push(t.object);break;case"log":e.push(this._newMessage(t.type))}},_addSpanData:function(t,e){r.isIE||("%c"==e.text.substring(e.text.length-2)?e.args[e.args.length-1]=this._stylesString(t.styles):(e.text+="%c",e.args.push(this._stylesString(t.styles))))},_newMessage:function(t){return{type:t||"log",text:"",args:[]}},_stylesString:function(t){var e,r,s="";for(r in t)e=t[r],r=this._fixCssStyleKey(r),"number"!=typeof e||n[r]||(e+="px"),s+=this._toDashKey(r)+":"+e+";";return s},_fixCssStyleKey:function(t){return t.replace(/-\w/g,function(t){return t.charAt(1).toUpperCase()})},_toDashKey:function(t){return t.replace(/[A-Z]/g,function(t){return"-"+t.toLowerCase()})}},"undefined"!=typeof window&&(window.console||(window.console={}),window.console.message=t)}();