Skip to content

Instantly share code, notes, and snippets.

@wassname
Last active July 25, 2016 02:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wassname/bea5fb2df62e91c376010cfa9e356106 to your computer and use it in GitHub Desktop.
Save wassname/bea5fb2df62e91c376010cfa9e356106 to your computer and use it in GitHub Desktop.
Snippet to inject jquery etc into page
/**
Put links to injectable scripts in the cdns array. Try searching on cdnjs.com
but if you need the latest you can use the github version via https://rawgit.com/.
This start with // so they word on https and http.
They are not minified so comment are visible during development.
**/
var cdns = [
/* polyfill */
'//cdnjs.cloudflare.com/ajax/libs/html5shiv/3.7.3/html5shiv.js',
'//cdnjs.cloudflare.com/ajax/libs/es5-shim/4.5.7/es5-shim.js',
'//cdnjs.cloudflare.com/ajax/libs/es6-shim/0.35.0/es6-shim.js',
// '//cdnjs.cloudflare.com/ajax/libs/babel-standalone/6.7.4/babel.js',
/* helpers */
'//cdnjs.cloudflare.com/ajax/libs/jquery/2.2.2/jquery.js',
'//cdnjs.cloudflare.com/ajax/libs/lodash.js/4.6.0/lodash.js',
// '//cdnjs.cloudflare.com/ajax/libs/mathjs/3.1.3/math.js',
// '//cdnjs.cloudflare.com/ajax/libs/alertify.js/0.5.0/alertify.js',
// '//cdnjs.cloudflare.com/ajax/libs/dat-gui/0.5.1/dat.gui.js',
'//cdnjs.cloudflare.com/ajax/libs/moment.js/2.12.0/moment.js',
'//cdnjs.cloudflare.com/ajax/libs/jstat/1.5.2/jstat.js',
// inject an html console into page (for use in "browsers" without it, via bookmarklet)
// '//cdnjs.cloudflare.com/ajax/libs/jquery.terminal/0.9.3/js/jquery.terminal-min.js',
/* viz */
// '//cdnjs.cloudflare.com/ajax/libs/highcharts/4.2.3/highcharts.js,'
// '//cdnjs.cloudflare.com/ajax/libs/d3/3.5.16/d3.js',
// '//cdnjs.cloudflare.com/ajax/libs/three.js/r75/three.js',
// '//cdnjs.cloudflare.com/ajax/libs/q.js/0.9.6/q.js',
// '//cdnjs.cloudflare.com/ajax/libs/datatables/1.10.11/js/jquery.dataTables.js',,
// '//cdnjs.cloudflare.com/ajax/libs/three.js/r58/three.js',
/* testing */
'//cdnjs.cloudflare.com/ajax/libs/sinon.js/1.15.4/sinon.js', // mocks, spies
'//cdnjs.cloudflare.com/ajax/libs/chai/3.5.0/chai.js',
// '//cdnjs.cloudflare.com/ajax/libs/qunit/1.18.0/qunit.js',
'//cdnjs.cloudflare.com/ajax/libs/mocha/2.4.5/mocha.js',
// '//cdnjs.cloudflare.com/ajax/libs/jshint/2.9.1/jshint.js',
'//rawgit.com/kangax/jscritic/gh-pages/jscritic.js',
/* reverse eng/ inspecting */
// '//cdnjs.cloudflare.com/ajax/libs/infect/0.4.6/infect.js', // https://github.com/amwmedia/infect.js
'//cdnjs.cloudflare.com/ajax/libs/javascript-hooker/0.2.3/ba-hooker.js'
// '//cdnjs.cloudflare.com/ajax/libs/deb.js/0.0.2/deb.js',
// '//cdnjs.cloudflare.com/ajax/libs/prettydiff/1.16.37/prettydiff.js',
// '//cdnjs.cloudflare.com/ajax/libs/gremlins.js/0.1.0/gremlins.js',
// '//cdnjs.cloudflare.com/ajax/libs/min.js/0.2.3/$.min.js',
]
function getScript(url, success) {
var script = document.createElement('script');
script.src = url;
var head = document.getElementsByTagName('head')[0];
var done = false;
script.onload = script.onreadystatechange = function () {
if (!done && (!this.readyState || this.readyState == 'loaded' || this.readyState == 'complete')) {
done = true;
console.log('done', url)
script.onload = script.onreadystatechange = null;
head.removeChild(script);
}
};
head.appendChild(script);
}
for (var i = 0; i < cdns.length; i++) {
getScript(cdns[i]);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment