Skip to content

Instantly share code, notes, and snippets.

@jagracey
Created November 22, 2019 21:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jagracey/e2d23e8b5c971fde7d9b32257253fa76 to your computer and use it in GitHub Desktop.
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.
/*
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