Last active
August 29, 2015 14:01
-
-
Save jwaliszko/811711b94a84408a6af3 to your computer and use it in GitHub Desktop.
Bookmarklet which displays downloads statistics of github binary 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
javascript: (function() { | |
window['releasesResponse'] = function(result) { | |
var body = ''; | |
for (var i = 0; i < result.data.length; i++) { | |
var assets = result.data[i].assets; | |
if (assets.length > 0) { | |
body += result.data[i].name + ':\n'; | |
for (var j = 0; j < assets.length; j++) { | |
body += assets[j].name + ' - ' + assets[j].download_count + ' downloads\n'; | |
} | |
} | |
} | |
body = (body == '' ? 'no releases downloaded' : body); | |
console.log(body); | |
alert(body); | |
}; | |
var url = window.location.href; | |
if (/^https:\/\/github.com\/[^\/]+\/[^\/]+\/releases$/i.test(url)) { | |
var script = document.createElement('script'); | |
script.src = url.replace('github.com', 'api.github.com/repos') + '?callback=releasesResponse'; | |
document.getElementsByTagName('head')[0].appendChild(script); | |
} else { | |
var error = 'invalid url schema of github repository releases - url should looks like: https://github.com/username/repository/releases'; | |
console.error(error); | |
alert(error); | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment