Skip to content

Instantly share code, notes, and snippets.

@aadityabhatia
Created November 18, 2012 19:56
Show Gist options
  • Select an option

  • Save aadityabhatia/4107130 to your computer and use it in GitHub Desktop.

Select an option

Save aadityabhatia/4107130 to your computer and use it in GitHub Desktop.
bookmarklet to inject jQuery into any page
(function() {
if(typeof jQuery!='undefined') {
return console.log('jQuery already present: v'+jQuery.fn.jquery);
}
if(typeof($) === 'function') {
console.log('$ already defined. Use $jq(), not $().');
}
var script=document.createElement('script');
script.src='http://code.jquery.com/jquery-latest.min.js';
var head=document.getElementsByTagName('head')[0],
done=false;
script.onload=script.onreadystatechange = function(){
if ( !done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete') ) {
done=true;
if (typeof jQuery=='undefined') {
console.log('jQuery not loaded');
} else {
console.log('jQuery loaded: v' + jQuery.fn.jquery);
}
script.onload = script.onreadystatechange = null;
head.removeChild(script);
}
};
head.appendChild(script);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment