Skip to content

Instantly share code, notes, and snippets.

@forivall
Created September 17, 2013 22:36
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 forivall/6601639 to your computer and use it in GitHub Desktop.
Save forivall/6601639 to your computer and use it in GitHub Desktop.
Requirejs bootstrap for userscripts
;(function (body) {
var el = document.createElement('script');
el.textContent = ';(' + body + ')();';
document.body.appendChild(el);
return el;
})(function() {
(function(body) {
if (typeof 'require' !== 'undefined' && require !== null) {
var el = document.createElement('script');
el.addEventListener('load', body);
el.setAttribute('src', '//cdnjs.cloudflare.com/ajax/libs/require.js/2.1.8/require.min.js');
} else {
body();
}
})(function() {
// <--
var usRequire = require.config({
context: 'myUserscript',
"paths": {
"jquery": "//ajax.googleapis.com/ajax/libs/jquery/2.0.0/jquery.min"
}
});
usRequire(['jquery'], function($) {
$.noop();
})
// -->
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment