Created
July 14, 2016 15:56
-
-
Save evandroamparo/07dab85820fb6ef61df4ed2ccbef20f0 to your computer and use it in GitHub Desktop.
Downloading a file in the latest release of a GitHub repository - http://stackoverflow.com/questions/24987542/is-there-a-link-to-github-for-downloading-a-file-in-the-latest-release-of-a-repo/26454035#26454035
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
$(document).ready(function () { | |
GetLatestReleaseInfo(); | |
}); | |
function GetLatestReleaseInfo() { | |
$.getJSON("https://api.github.com/repos/ShareX/ShareX/releases/latest").done(function (release) { | |
var asset = release.assets[0]; | |
var downloadCount = 0; | |
for (var i = 0; i < release.assets.length; i++) { | |
downloadCount += release.assets[i].download_count; | |
} | |
var oneHour = 60 * 60 * 1000; | |
var oneDay = 24 * oneHour; | |
var dateDiff = new Date() - new Date(asset.updated_at); | |
var timeAgo; | |
if (dateDiff < oneDay) | |
{ | |
timeAgo = (dateDiff / oneHour).toFixed(1) + " hours ago"; | |
} | |
else | |
{ | |
timeAgo = (dateDiff / oneDay).toFixed(1) + " days ago"; | |
} | |
var releaseInfo = release.name + " was updated " + timeAgo + " and downloaded " + downloadCount.toLocaleString() + " times."; | |
$(".sharex-download").attr("href", asset.browser_download_url); | |
$(".release-info").text(releaseInfo); | |
$(".release-info").fadeIn("slow"); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment