forked from rwblackburn/inline-console
-
Notifications
You must be signed in to change notification settings - Fork 0
/
inline-console.min.js
1 lines (1 loc) · 3.65 KB
/
inline-console.min.js
1
!function(){var e,t,n,o,l,s,c,i=240,r=[],d=0,a=0,p=(new Date).getTime(),u=console.log,y=console.debug,g=console.warn,m=console.info,f=console.error;c=function(e,t){for(var n=t.parentNode;null!=n;){if(n==e)return!0;n=n.parentNode}return!1},n=function(){if(!e){var n=document.createElement("h3"),o=document.createElement("button");t=document.createElement("div"),e=document.createElement("div"),t.appendChild(n),t.appendChild(e),t.style.backgroundColor="#333333",t.style.color="#cccccc",t.style.position="fixed",t.style.bottom="0",t.style.right="0",t.style.left="0",t.style.clear="both",o.innerHTML="clear",o.style.fontSize="0.5em",o.style["float"]="right",o.style.color="black",o.onclick=s,n.innerHTML="Inline Console",n.style.padding="0.3em",n.style.margin="0",n.style.fontFamily="monospace",n.appendChild(o),e.style.backgroundColor="black",e.style.border="0",e.style.color="#00ff00",e.style.height=i+"px",e.style.resize="none",e.style.overflowY="auto",e.style.fontFamily="monospace",document.body.appendChild(t)}},s=function(){e.innerHTML=null},l=function(e,t,n){var o=document.getElementById(t),l=document.getElementById(t+"-hidden");o.style.display?(o.style.display=null,l.style.display="none",n.innerHTML="hide"):(o.style.display="none",l.style.display=null,n.innerHTML="show")},o=function(t,o,s){var c,r=document.createElement("div"),a=t+"-"+ ++d,u=JSON.stringify(o[0]),y=document.createElement("button"),g=document.createElement("hr"),m=(new Date).getTime();if(n(),r.style.clear="both",r.style.margin="0",r.style.padding="0",s&&(r.style.color=s),r.innerHTML+="<strong>"+t+"</strong> ["+(m-p)+'ms]: <span style="display:none;" id="'+a+'-hidden">'+u.substring(0,48)+"...</span>",1===o.length)c=document.createElement("span"),c.id=a,c.innerHTML=u,r.appendChild(c);else if(o.length>1){c=document.createElement("ol"),c.id=a,c.style.margin="0",c.style.padding="0";for(var f,h=0,E=o.length;E>h;h++)f=document.createElement("li"),f.innerHTML=JSON.stringify(o[h]),c.appendChild(f);r.appendChild(c)}(u.length>64||o.length>1)&&(y.onclick=function(e){l(e,a,y)},y.innerHTML="hide",y.style["float"]="right",y.style.color="black",y.style.fontSize="0.7em",r.appendChild(y)),g.style.clear="both",g.style.margin="0",g.style.padding="0",r.appendChild(g),e.appendChild(r),r.clientHeight>i&&l(null,a,y),e.scrollTop=e.scrollHeight},console.log=function(){o("LOG",arguments),u.apply(console,arguments)},console.debug=function(){o("DEBUG",arguments,"#cccccc"),y.apply(console,arguments)},console.warn=function(){o("WARN",arguments,"#ff9900"),g.apply(console,arguments)},console.info=function(){o("INFO",arguments,"#0066ff"),m.apply(console,arguments)},console.error=function(){o("ERROR",arguments,"#ff0000"),f.apply(console,arguments)};for(var h=0,E=r.length;E>h;h++)document.addEventListener(r[h],function(e){c(t,e.target)||o("EVENT",["An event type ""+e.type+"" was triggered by a ""+e.target.nodeName+"" node."],"#cccccc")},!0);window.onerror=function(e,t,n){o("ERROR",[e,t,n],"#ff0000")},XMLHttpRequest.prototype.oldOpen=XMLHttpRequest.prototype.open,XMLHttpRequest.prototype.oldSend=XMLHttpRequest.prototype.send,XMLHttpRequest.prototype.getId=function(){return this.threadId||(this.threadId=++a),("00"+this.threadId).slice(-3)},XMLHttpRequest.prototype.open=function(e,t,n,l,s){o("HTTP",["Opening Connection #"+this.getId(),{method:e,url:t,async:n,user:l,password:s}],"#cccccc"),this.oldOpen(e,t,n,l,s)},XMLHttpRequest.prototype.send=function(e){this.addEventListener("load",function(){o("HTTP",["Connection #"+this.getId()+" Completed Successfully: "+this.status],"#cccccc")},!1),this.addEventListener("error",function(){o("HTTP-ERROR",["Connection #"+this.getId()+" Failed: "+this.status],"#ff0000")},!1),this.oldSend(e)}}();