-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathConsole.min.js
7 lines (7 loc) · 6.41 KB
/
Console.min.js
1
2
3
4
5
6
7
/*!
* Name: Console.js
* Info: A simple but useful extension for the JavaScript console with a stack trace and more.
* Author: Gabriel Nahmias (http://terrasoftlabs.com|gabriel@terrasoftlabs.com)
* Version: 1.7a
*/
(function(d){var a={_options:{}},b={alwaysShowURL:false,enabled:true,showInfo:true,enableStackTrace:true,collapsed:true,ignoreInternalFuncs:true,spacing:false,useOldStackTrace:false},e=navigator.userAgent,c={firefox:/firefox/gi.test(e),ie:/msie/gi.test(e),ios:/i(phone|pad)/gi.test(e),webkit:/webkit/gi.test(e)};a.ver=a.version=1.4;function f(){for(var h=1;h<arguments.length;h++){for(var g in arguments[h]){if(arguments[h].hasOwnProperty(g)){arguments[0][g]=arguments[h][g]}}}return arguments[0]}f(a._options,b);if(!String.prototype.format){String.prototype.format=function(){var h=this.toString(),g=typeof arguments[0],g=(("string"==g||"number"==g)?arguments:arguments[0]);if(!arguments.length){return h}for(arg in g){h=h.replace(RegExp("\\{"+arg+"\\}","gi"),g[arg])}return h}}if(!String.prototype.times){String.prototype.times=function(){var j=this.toString(),g="",k=arguments[0];if(!arguments.length){return j}for(var h=0;h<k;h++){g+=j}return g}}a._=function(h){var p=a.getOption("enabled"),u=(typeof d.console[h]!=="undefined");if(typeof d.console!=="undefined"){if(p){if(typeof h==="string"){if(u){var r=((typeof arguments!=="undefined")?Array.prototype.slice.call(arguments,1):[]),n=a.stackTrace().split("\n"),v,j=((c.webkit)?3:2),l="color:black;",t="color:{0}; font-weight:bold;",g="";if(c.firefox){v=n[j].replace(/(.*):/,"$1@").split("@")}else{if(c.webkit&&!c.ios){v=n[j].replace("at ","").replace(")","").replace(/( \()/gi,"@").replace(/(.*):(\d*):(\d*)/,"$1@$2@$3").split("@")}else{v=""}}if(a.getOption("showInfo")&&!a.getOption("enableStackTrace")){var o=v[0].trim(),q=v[1].trim(),q=((!a.getOption("alwaysShowURL")&&d.location.href==q)?"this page":q),k=v[2].trim(),i;if(c.webkit){i=v[3].trim()}d.console.info("%cOn line %c{0}%c{1}%c{2}%c of %c{3}%c inside the %c{4}%c function:".format(k,((c.webkit)?", column ":""),((c.webkit)?i:""),q,o),l,t.format("red"),l,t.format("purple"),l,t.format("green"),l,t.format("blue"),l)}if(a.getOption("ignoreInternalFuncs")){if(c.webkit){if(arguments.callee.name!="_"){n.shift()}n.shift()}n.shift();n.shift()}g=n.join(((a.getOption("spacing"))?"\n\n":"\n")).trim();trace=typeof trace!=="undefined"?trace:true;d.console[h].apply(d.console,r);if(a.getOption("enableStackTrace")&&!c.ie){var m="color:red; font-weight: bold;",s="%c Stack Trace"+" ".times(70);if(a.getOption("collapsed")){d.console.groupCollapsed(s,m)}else{d.console.group(s,m)}if(!a.getOption("useOldStackTrace")&&h!="trace"){d.console.trace()}else{d.console.debug("%c"+g,"color: #666666; font-style: italic;")}d.console.groupEnd()}return true}else{throw new Error('"{0}" does not exist in intrinsic console object.'.format(h))}}else{throw new Error("Method must be a string.")}}}else{throw new Error("Console functionality is not available in this browser.")}return false};a.stackTrace=function(){var h=new Error(),g;if(typeof h.stack==="undefined"){g=""}else{g=h.stack}return g};a.getOption=function(g){if(typeof a._options[g]!=="undefined"){return a._options[g]}else{throw new Error("Option does not exist.")}return null};a.setOption=function(g,h){if(typeof h==="boolean"){a._options[g]=h;return true}else{throw new Error("Value must be a boolean (true/false).")}return false};a.assert=function(){var g=Array.prototype.slice.call(arguments,0);g.unshift("assert");if(a._.apply(a,g)){return true}else{return false}};a.clear=function(){var g=Array.prototype.slice.call(arguments,0);g.unshift("clear");if(a._.apply(a,g)){return true}else{return false}};a.count=function(){if(c.ie){return null}var g=Array.prototype.slice.call(arguments,0);g.unshift("count");if(a._.apply(a,g)){return true}else{return false}};a.debug=function(){var g=Array.prototype.slice.call(arguments,0);g.unshift((c.ie)?"dir":"debug");if(a._.apply(a,g)){return true}else{return false}};a.dir=function(){var g=Array.prototype.slice.call(arguments,0);g.unshift("dir");if(a._.apply(a,g)){return true}else{return false}};a.dirxml=function(){if(c.ie){return null}var g=Array.prototype.slice.call(arguments,0);g.unshift("dirxml");if(a._.apply(a,g)){return true}else{return false}};a.error=function(){var g=Array.prototype.slice.call(arguments,0);g.unshift("error");if(a._.apply(a,g)){return true}else{return false}};a.exception=function(){if(c.ie){return null}var g=Array.prototype.slice.call(arguments,0);g.unshift("exception");if(a._.apply(a,g)){return true}else{return false}};a.group=function(){if(c.ie){return null}var g=Array.prototype.slice.call(arguments,0);g.unshift("group");if(a._.apply(a,g)){return true}else{return false}};a.groupCollapsed=function(){if(c.ie){return null}var g=Array.prototype.slice.call(arguments,0);g.unshift("groupCollapsed");if(a._.apply(a,g)){return true}else{return false}};a.groupEnd=function(){if(c.ie){return null}var g=Array.prototype.slice.call(arguments,0);g.unshift("groupEnd");if(a._.apply(a,g)){return true}else{return false}};a.info=function(){var g=Array.prototype.slice.call(arguments,0);g.unshift("info");if(a._.apply(a,g)){return true}else{return false}};a.log=function(){var g=Array.prototype.slice.call(arguments,0);g.unshift("log");if(a._.apply(a,g)){return true}else{return false}};a.profile=function(){var g=Array.prototype.slice.call(arguments,0);g.unshift("profile");if(a._.apply(a,g)){return true}else{return false}};a.profileEnd=function(){var g=Array.prototype.slice.call(arguments,0);g.unshift("profileEnd");if(a._.apply(a,g)){return true}else{return false}};a.table=function(){if(c.ie){return null}var g=Array.prototype.slice.call(arguments,0);g.unshift("table");if(a._.apply(a,g)){return true}else{return false}};a.time=function(){if(c.ie){return null}var g=Array.prototype.slice.call(arguments,0);g.unshift("time");if(a._.apply(a,g)){return true}else{return false}};a.timeEnd=function(){if(c.ie){return null}var g=Array.prototype.slice.call(arguments,0);g.unshift("timeEnd");if(a._.apply(a,g)){return true}else{return false}};a.timeStamp=function(){if(c.ie){return null}var g=Array.prototype.slice.call(arguments,0);g.unshift("timeStamp");if(a._.apply(a,g)){return true}else{return false}};a.trace=function(){if(c.ie){return null}var g=Array.prototype.slice.call(arguments,0);g.unshift("trace");if(a._.apply(a,g)){return true}else{return false}};a.warn=function(){var g=Array.prototype.slice.call(arguments,0);g.unshift("warn");if(a._.apply(a,g)){return true}else{return false}};d.Console=a})(window);