Created
December 22, 2016 10:23
-
-
Save vineetchoudhary/85672cc16631731270fe03968b624a05 to your computer and use it in GitHub Desktop.
Get latest release download
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
<script type="text/javascript"> | |
$(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"); | |
}); | |
} | |
</script> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment