Last active
November 9, 2018 12:14
-
-
Save techieshark/45d6f183f80835757336 to your computer and use it in GitHub Desktop.
jquery-and-lodash-in-console
This file contains 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
// For quickly trying things out in the browser, jQuery and Lo-Dash (like Underscore.js) are great. | |
// Read the code below (never copy & paste code you don't trust), | |
// then you can copy & paste it into the browser console to load jQuery & lodash. | |
(function () { | |
var jq = document.createElement('script'); | |
jq.src = 'https://code.jquery.com/jquery-2.1.4.js'; | |
document.getElementsByTagName('head')[0].appendChild(jq); | |
// jQuery should be available via "jQuery" (and we'll set up the $ alias in the defer() function) | |
var ld = document.createElement('script'); | |
ld.src = 'https://cdnjs.cloudflare.com/ajax/libs/lodash.js/3.10.1/lodash.js'; | |
document.getElementsByTagName('head')[0].appendChild(ld); | |
// lodash should be available via "_". | |
var defer = function () { | |
if (window.jQuery) { | |
jQuery.noConflict(); | |
$ = jQuery; | |
// jQuery should be available via "$". | |
} else { | |
setTimeout(function () { | |
defer(); | |
}, 50); | |
} | |
}; | |
defer(); // wait for jQuery to download, then set up $ alias | |
console.log('jQuery ($) and lodash (_) should now be available in your browser console.'); | |
console.log('If not, there may be a Content Security Policy error.'); | |
console.log('See: https://jquery.com https://lodash.com for documentation.') | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Update: check out "Injecta" extension for chrome. There's also "Script Injector", and "Custom Javascript for Websites".