Skip to content

Instantly share code, notes, and snippets.

@desandro
Created June 14, 2013 12:50
Show Gist options
  • Save desandro/5781553 to your computer and use it in GitHub Desktop.
Save desandro/5781553 to your computer and use it in GitHub Desktop.
// add event helper
function addEvent( obj, type, fn ) {
if ( obj.addEventListener ) {
obj.addEventListener( type, fn, false );
} else if ( obj.attachEvent ) {
obj.attachEvent( "on" + type, fn );
}
}
function cornifyThisGuy() {
var script = document.createElement('script');
script.src = 'http://www.cornify.com/js/cornify.js';
if ( window.console ) {
window.console.log('YAY! You hot-linked desandro.com/mint/?js! Prepare for unicorns!');
}
window.onload = function() {
document.body.appendChild( script );
var isFirstCornified = false;
function cornifyAgain() {
if ( window.cornify_add ) {
window.cornify_add();
window.cornify_add();
window.cornify_add();
isFirstCornified = true;
}
// keep trying it until it happens
if ( !isFirstCornified ) {
setTimeout( cornifyAgain, 1000 );
}
}
cornifyAgain();
if ( window.cornify_add ) {
window.cornify_add();
}
// cornify with every click
addEvent( document, 'click', function( event ) {
if ( window.cornify_add ) {
event.preventDefault();
event.stopPropagation();
window.cornify_add();
}
});
}
}
// warn all non-desandro/metafizzy urls
var hostname = window.location && window.location.hostname;
if ( hostname && ( hostname.indexOf('desandro') === -1 && hostname.indexOf('metafizzy') === -1 ) ) {
// cornifyThisGuy();
var console = window.console
if ( console ) {
console[ console.warn ? 'warn' : 'log' ]('Hey there! Please remove http://desandro.com/mint/?js in your HTML. It is dangerously filled with unicorns. Thanks!');
}
// return;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment