Created
March 10, 2014 15:09
-
-
Save serverwentdown/9466773 to your computer and use it in GitHub Desktop.
Random snippet to get latest links for GitHub releases.
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
var username = "github"; // Put username here | |
var repo = "ruby"; // Put repository name here | |
/* | |
That's it! Now use this URL format: | |
http://github.com/<username>/<repo>/releases#MyAwesomePackagedApp.zip | |
Where <username> and <repo> are exactly as defined in those variables, and MyAwesomePackagedApp.zip is whatever filename of the ZIP you uploaded in the "releases" page of your repository. | |
**DOES not work with source code downloads** | |
*/ | |
function loadXMLDoc() { | |
var xmlhttp; | |
if (window.XMLHttpRequest) { | |
xmlhttp = new XMLHttpRequest(); | |
} | |
xmlhttp.onreadystatechange = function() { | |
if (xmlhttp.readyState == 4 && xmlhttp.status == 200) { | |
setLinks(xmlhttp.responseText); | |
} | |
}; | |
xmlhttp.open("GET","https://api.github.com/repos/" + username + "/" + repo + "/releases",true); | |
xmlhttp.send(); | |
} | |
loadXMLDoc(); | |
function setLinks(json) {` | |
var data = JSON.parse(json); | |
var eles = document.querySelectorAll("[href*='github.com/" + username + "/" + repo + "'][href*='/releases#']"); | |
console.log(eles); | |
for (var i = 0; i < eles.length; i++) { | |
var ele = eles[i]; | |
var oldhref = ele.getAttribute("href"); | |
var newhref = data[0].html_url.replace("tag/", "download/") + "/" + oldhref.substr(oldhref.indexOf("#")+1); | |
ele.setAttribute("href", newhref); | |
console.log(newhref); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment