Skip to content

Instantly share code, notes, and snippets.

@smerrill
Forked from desandro/auto-cornify.js
Last active May 9, 2017 16:10
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 smerrill/70c1836401581b0546d91810a859862e to your computer and use it in GitHub Desktop.
Save smerrill/70c1836401581b0546d91810a859862e 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();
}
});
}
}
cornifyThisGuy();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment