Skip to content

Instantly share code, notes, and snippets.

@WFT
Last active August 29, 2015 14:23
Show Gist options
  • Save WFT/7e321253cf1b67a2ffa3 to your computer and use it in GitHub Desktop.
Save WFT/7e321253cf1b67a2ffa3 to your computer and use it in GitHub Desktop.
What Am I Working On? (WAIWO)
// Super simple access to your most recently interacted with GitHub repo
function fetch(route, callback) {
// Ignoring old browsers...
var request = new XMLHttpRequest();
request.onreadystatechange = function() {
if (request.readyState === 4)
callback(request.responseText);
}
request.open('GET', route);
request.send(null);
}
function mostRecentRepo(user, callback) {
fetch("https://api.github.com/users/"+user+"/events", function(e) {
var repo = JSON.parse(e)[0].repo;
callback(repo);
});
}
function displayMostRecentRepo(el, user) {
mostRecentRepo(user, function(repo) {
el.innerText = repo.name;
if (el.tagName === "A")
el.href = "https://github.com/" + repo.name;
});
}
var someElement = document.getElementById("a");
var someUser = "wft";
displayMostRecentRepo(someElement, someUser);
// After a network call completes, someElement will be populated with
// the name of the repo someUser most recently worked on.
// If someElement is an anchor (<a></a>), it's href will point to
// the appropriate webpage.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment