Skip to content

Instantly share code, notes, and snippets.

@seaside98
Created April 21, 2014 01:22
Show Gist options
  • Save seaside98/11129704 to your computer and use it in GitHub Desktop.
Save seaside98/11129704 to your computer and use it in GitHub Desktop.
Import a script or stylesheet from GitHub
/* A useful script for pulling directly from GitHub to Wikia.
*
* Use by calling:
* importGitHub('LMBW/Parallel/Parallel.css');
* or
* importGitHub('LMBW/Parallel/Parallel.js');
*/
function importGitHub( path ) {
path = path.replace(/(.*?\/.*?\/)/, '$1contents/');
$.ajax({
url: 'http://api.github.com/repos/' + path,
dataType: 'jsonp',
success: function( results ){
var content = atob(results.data.content);
var type = this.url.replace(/.*?\/\/.*?\/.*?\./, '').replace(/\?.*/, '');
if ( type == 'css' ) {
$('body').append( '<style >' + content + '</style>' );
} else {
var script = document.createElement('script');
script.text = content;
document.body.appendChild(script);
}
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment