Last active
August 29, 2015 14:20
-
-
Save devpuppy/adeaec2ddcf13e11b51e to your computer and use it in GitHub Desktop.
Tools for working with JavaScript gists
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
function ajax(url, callback) { | |
var xhr = new XMLHttpRequest(); | |
xhr.onreadystatechange = function() { | |
if (xhr.readyState === 4) { | |
callback(xhr.responseText); | |
} | |
} | |
xhr.open('GET', url, true); | |
xhr.send(); | |
} | |
function gist(id, callback) { | |
var url = 'https://api.github.com/gists/'+id; | |
ajax(url, function(json) { | |
var gist = JSON.parse(json); | |
for (var i in gist.files) { | |
var file = gist.files[i]; | |
if (file.language == 'JavaScript') { | |
ajax(file.raw_url, callback); | |
} | |
} | |
}); | |
} | |
function evalGist(id) { | |
gist(id, eval); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment