-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make requests Async Fixes #1 - TAG 1.0.0
- Loading branch information
Showing
2 changed files
with
30 additions
and
19 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,34 @@ | ||
//TODO async | ||
var xmlHttp = new XMLHttpRequest(); | ||
xmlHttp.onreadystatechange = function () { | ||
switch (xmlHttp.readyState) { | ||
case 0 : // UNINITIALIZED | ||
case 1 : // LOADING | ||
case 2 : // LOADED | ||
case 3 : // INTERACTIVE | ||
break; | ||
case 4 : // COMPLETED | ||
var releases = JSON.parse( xmlHttp.responseText ); | ||
var downloadMap = []; | ||
for (var i in releases) { | ||
for (var j in releases[i].assets) { | ||
downloadMap[releases[i].assets[j].browser_download_url] = releases[i].assets[j].download_count; | ||
} | ||
} | ||
var els = document.getElementsByTagName("a"); | ||
for (var i = 0, l = els.length; i < l; i++) { | ||
var el = els[i]; | ||
if ( el.href in downloadMap ) { | ||
var dwnCount = document.createElement( 'small' ); | ||
dwnCount.appendChild( document.createTextNode( ' - ' + downloadMap[el.href] + ' downloads' ) ) | ||
el.appendChild( dwnCount ); | ||
} | ||
} | ||
break; | ||
default: console.log( 'Error: GitHub Release Donwload Count Request Errored.' ); | ||
} | ||
}; | ||
xmlHttp.open( "GET", | ||
document.URL.replace( '//github.com', '//api.github.com/repos' ).split( '/tag/' )[0], | ||
false | ||
true | ||
); | ||
xmlHttp.send( null ); | ||
var releases = JSON.parse( xmlHttp.responseText ); | ||
var downloadMap = []; | ||
for (var i in releases) { | ||
for (var j in releases[i].assets) { | ||
downloadMap[releases[i].assets[j].browser_download_url] = releases[i].assets[j].download_count; | ||
} | ||
} | ||
var els = document.getElementsByTagName("a"); | ||
for (var i = 0, l = els.length; i < l; i++) { | ||
var el = els[i]; | ||
if ( el.href in downloadMap ) { | ||
var dwnCount = document.createElement( 'small' ); | ||
dwnCount.appendChild( document.createTextNode( ' - ' + downloadMap[el.href] + ' downloads' ) ) | ||
el.appendChild( dwnCount ); | ||
} | ||
} |