Created
November 22, 2019 21:19
-
-
Save jagracey/e2d23e8b5c971fde7d9b32257253fa76 to your computer and use it in GitHub Desktop.
It's Christmas time again. That means setting up your Christmas decorators. Let's get those console logs of yours spruced up.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Lets have a little Christmas fun in the console. | |
From the Wisdom team | |
https://GetWisdom.io | |
*/ | |
(function ChristmasConsole (){ | |
function getRandEmoji() { | |
const EMOJIES = ['🦌🦌🦌', '🎅', '🎄🎄']; | |
return EMOJIES[ Math.random() * EMOJIES.length |0 ]; | |
} | |
function getRandStyle() { | |
const randColor = Math.random() > 0.5 ? '#CC172B' : '#0E5818'; | |
return 'color: '+randColor+';'; | |
} | |
const log = window.console.log; | |
window.console.log = function() { | |
const args = Array.prototype.slice.call(arguments); | |
const style = getRandStyle(); | |
args.push(getRandEmoji()); | |
if (window.navigator && window.navigator.vendor === 'Google Inc.') { | |
var formatting = ''; | |
const valueArgs = []; | |
args.forEach(x => { | |
let formatter; | |
if (typeof x === 'object') { | |
formatter = '%o '; | |
} | |
else if (typeof x === 'number') { | |
formatter = '%c%f '; | |
valueArgs.push('color: blue;'); | |
} | |
else { | |
formatter = '%c%s '; | |
valueArgs.push(style); | |
} | |
formatting += formatter; | |
valueArgs.push(x); | |
}); | |
return log.apply(window.console, [].concat([formatting], valueArgs)); | |
} | |
else { | |
return log.apply(window.console, args); | |
} | |
} | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment