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.7 KB
/
inline-console.min.js
1
!function(){var e,t,n,o,l,s,i,c=240,r=[],d=0,a=0,p=(new Date).getTime(),u=console.log,y=console.debug,g=console.warn,f=console.info,m=console.error,t=document.createElement("div");i=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");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=c+"px",e.style.resize="none",e.style.overflowY="auto",e.style.fontFamily="monospace"}},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 i,r=document.createElement("div"),a=t+"-"+ ++d,u=JSON.stringify(o[0]),y=document.createElement("button"),g=document.createElement("hr"),f=(new Date).getTime();if(n(),r.style.clear="both",r.style.margin="0",r.style.padding="0",r.style.textAlign="left",s&&(r.style.color=s),r.innerHTML+="<strong>"+t+"</strong> ["+(f-p)+'ms]: <span style="display:none;" id="'+a+'-hidden">'+u.substring(0,48)+"...</span>",1===o.length)i=document.createElement("span"),i.id=a,i.innerHTML=u,r.appendChild(i);else if(o.length>1){i=document.createElement("ol"),i.id=a,i.style.margin="0",i.style.padding="0";for(var m,h=0,E=o.length;E>h;h++)m=document.createElement("li"),m.innerHTML=JSON.stringify(o[h]),i.appendChild(m);r.appendChild(i)}(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>c&&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"),f.apply(console,arguments)},console.error=function(){o("ERROR",arguments,"#ff0000"),m.apply(console,arguments)};for(var h=0,E=r.length;E>h;h++)document.addEventListener(r[h],function(e){i(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")},window.onload=function(){document.body.appendChild(t)},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)}}();