2 var ffSupport, formats, getOrderedMatches, hasMatches, isFF, isIE, isOpera, isSafari, log, makeArray, operaSupport, safariSupport, stringToArgs, _log;
3 if (!(window.console && window.console.log)) {
9 makeArray(arguments).forEach(function(arg) {
10 if (typeof arg === 'string') {
11 return args = args.concat(stringToArgs(arg));
13 return args.push(arg);
16 return _log.apply(window, args);
19 return console.log.apply(console, makeArray(arguments));
21 makeArray = function(arrayLikeThing) {
22 return Array.prototype.slice.call(arrayLikeThing);
26 regex: /\*([^\*]+)\*/,
27 replacer: function(m, p1) {
28 return "%c" + p1 + "%c";
31 return ['font-style: italic', ''];
34 regex: /\_([^\_]+)\_/,
35 replacer: function(m, p1) {
36 return "%c" + p1 + "%c";
39 return ['font-weight: bold', ''];
42 regex: /\`([^\`]+)\`/,
43 replacer: function(m, p1) {
44 return "%c" + p1 + "%c";
47 return ['background: rgb(255, 255, 219); padding: 1px 5px; border: 1px solid rgba(0, 0, 0, 0.1)', ''];
50 regex: /\[c\=(?:\"|\')?((?:(?!(?:\"|\')\]).)*)(?:\"|\')?\]((?:(?!\[c\]).)*)\[c\]/,
51 replacer: function(m, p1, p2) {
52 return "%c" + p2 + "%c";
54 styles: function(match) {
55 return [match[1], ''];
59 hasMatches = function(str) {
62 formats.forEach(function(format) {
63 if (format.regex.test(str)) {
64 return _hasMatches = true;
69 getOrderedMatches = function(str) {
72 formats.forEach(function(format) {
74 match = str.match(format.regex);
82 return matches.sort(function(a, b) {
83 return a.match.index - b.match.index;
86 stringToArgs = function(str) {
87 var firstMatch, matches, styles;
89 while (hasMatches(str)) {
90 matches = getOrderedMatches(str);
91 firstMatch = matches[0];
92 str = str.replace(firstMatch.format.regex, firstMatch.format.replacer);
93 styles = styles.concat(firstMatch.format.styles(firstMatch.match));
95 return [str].concat(styles);
97 isSafari = function() {
98 return /Safari/.test(navigator.userAgent) && /Apple Computer/.test(navigator.vendor);
100 isOpera = function() {
101 return /OPR/.test(navigator.userAgent) && /Opera/.test(navigator.vendor);
104 return /Firefox/.test(navigator.userAgent);
107 return /MSIE/.test(navigator.userAgent);
109 safariSupport = function() {
111 m = navigator.userAgent.match(/AppleWebKit\/(\d+)\.(\d+)(\.|\+|\s)/);
115 return 537.38 <= parseInt(m[1], 10) + (parseInt(m[2], 10) / 100);
117 operaSupport = function() {
119 m = navigator.userAgent.match(/OPR\/(\d+)\./);
123 return 15 <= parseInt(m[1], 10);
125 ffSupport = function() {
126 return window.console.firebug || window.console.exception;
128 if (isIE() || (isFF() && !ffSupport()) || (isOpera() && !operaSupport()) || (isSafari() && !safariSupport())) {