Last active
August 29, 2015 14:23
-
-
Save WFT/7e321253cf1b67a2ffa3 to your computer and use it in GitHub Desktop.
What Am I Working On? (WAIWO)
This file contains hidden or 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
// 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