Created
April 21, 2014 01:22
-
-
Save seaside98/11129704 to your computer and use it in GitHub Desktop.
Import a script or stylesheet from GitHub
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
/* 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