Created
November 18, 2012 19:56
-
-
Save aadityabhatia/4107130 to your computer and use it in GitHub Desktop.
bookmarklet to inject jQuery into any page
This file contains hidden or 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
| (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