Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dscho/5d171ec286a52ca4c699477cceaebe20 to your computer and use it in GitHub Desktop.
Save dscho/5d171ec286a52ca4c699477cceaebe20 to your computer and use it in GitHub Desktop.
Show download counts of GitHub releases (Tampermonkey script)
// ==UserScript==
// @name Show download counts of GitHub releases
// @description Displays the download count of GitHub's release.
// @version 0.3
// @source https://gist.github.com/dscho/5d171ec286a52ca4c699477cceaebe20
// @updateURL https://gist.github.com/dscho/5d171ec286a52ca4c699477cceaebe20/raw/github-release-download-counts.user.js
// @downloadURL https://gist.github.com/dscho/5d171ec286a52ca4c699477cceaebe20/raw/github-release-download-counts.user.js
// @namespace http://tampermonkey.net/
// @author Kusaanko, Johannes Schindelin
// @match https://github.com/*/*/releases*
// @grant none
// @require https://code.jquery.com/jquery-3.3.1.min.js
// ==/UserScript==
$(function() {
const match = location.href.match(/^https:\/\/github\.com\/([^/]+\/[^/]+)\//);
if (!match) return;
const downloadCounts = {};
$.ajax({
url: `https://api.github.com/repos/${match[1]}/releases`,
type: 'GET'
}).done((data) => {
for (const release of Object.values(data)) {
for (const asset of Object.values(release['assets'])) {
const fileName = asset['browser_download_url'].replace(/.*\//, '');
downloadCounts[fileName] = asset['download_count'];
}
}
const updateSpans = () => {
$('span').each(function(i, elem) {
const count = downloadCounts[$(this).text()];
if(count !== undefined) {
$(this).after(`<span style="color: #24292e; vertical-align: top; font-size: 70%">&nbsp;${count.toLocaleString()}&nbsp;downloads</span>`);
}
});
}
updateSpans();
new MutationObserver((events, observer) => {
events.map((event) => {
if (event.type === 'childList' && event.target && event.target.tagName === 'DIV') {
updateSpans();
}
})
}).observe(document, { attributes: true, childList: true, subtree: true });
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment