Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion css/main.css
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
html * {
font-family: 'Roboto', sans-serif;
font-family: 'Roboto', 'Noto Sans SC', 'Microsoft YaHei', '微软雅黑', SimHei, sans-serif;
}

a, a:hover {
Expand Down
34 changes: 24 additions & 10 deletions index.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
<!DOCTYPE html>
<html>
<head>
<title>Github Release Stats</title>
<meta charset="UTF-8">
<title id="page-title">Github Release Stats</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="Get the latest release stats like download counts, release dates, author on any Github project">
<meta name="keywords" content="Github, release, download, count">
<meta name="description" id="page-description" content="Get the latest release stats like download counts, release dates, author on any Github project">
<meta name="keywords" id="page-keywords" content="Github, release, download, count">
<link rel="icon" href="img/favicon.ico">
<link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Mono" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css?family=Roboto|Roboto+Mono&display=swap" rel="stylesheet" type="text/css">
<link href="https://fonts.googleapis.com/css2?family=Noto+Sans+SC:wght@400;700&display=swap" rel="stylesheet">
<link rel="stylesheet" href="third-party/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="css/main.css">
</head>
Expand All @@ -22,15 +24,26 @@
</button>
<a class="navbar-brand" href=".">
<span class="glyphicon glyphicon-stats"></span>&nbsp;
Github Release Stats
<span id="navbar-title">Github Release Stats</span>
</a>
</div>
<div class="collapse navbar-collapse" id="main-navbar">
<ul class="nav navbar-nav navbar-right">
<li class="dropdown">
<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" aria-expanded="false">
<span class="glyphicon glyphicon-globe"></span>&nbsp;
<span id="lang-display">Language</span>
<span class="caret"></span>
</a>
<ul class="dropdown-menu" role="menu">
<li><a href="#" onclick="changeLang('en'); return false;">English</a></li>
<li><a href="#" onclick="changeLang('zh'); return false;">中文</a></li>
</ul>
</li>
<li>
<a href="https://github.com/Somsubhra/github-release-stats" target="_blank">
<span class="glyphicon glyphicon-eye-open"></span>&nbsp;
View project on Github
<span id="view-github">View project on Github</span>
</a>
</li>
</ul>
Expand All @@ -40,7 +53,7 @@
<div class="container">
<div class="row" id="search">
<div class="col-md-4 col-md-offset-4">
<h1>Enter project details...</h1>
<h1 id="enter-details">Enter project details...</h1>
<div class="form form-inline">
<div class="form-group">
<input type="text" class="form-control" id="username" placeholder="Github username">
Expand All @@ -53,11 +66,11 @@ <h1>Enter project details...</h1>
</div>
</div>
<div class="row" id="description">
<h1>...and get the latest release stats like download counts, release dates, authors for any Github project.</h1>
<h1 id="desc-text">...and get the latest release stats like download counts, release dates, authors for any Github project.</h1>
</div>
<div class="row" id="title">
<h1><span class="username"></span>/<span class="repository"></span></h1>
<span class="description">release stats</span>
<span class="description" id="title-description">release stats</span>
</div>
<div class="row" id="ads">
<div class="col-md-6 col-md-offset-2">
Expand All @@ -82,7 +95,7 @@ <h1><span class="username"></span>/<span class="repository"></span></h1>
<li><a id="get-next-results-button" href="#">Older</a></li>
</ul>
<div id="per-page">
<label class="">Per page</label>
<label id="per-page-label" class="">Per page</label>
<select class="form-control">
<option>5</option>
<option>10</option>
Expand All @@ -107,6 +120,7 @@ <h1><span class="username"></span>/<span class="repository"></span></h1>
<script type="text/javascript" src="third-party/jquery/jquery-1.11.1.min.js"></script>
<script type="text/javascript" src="third-party/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="third-party/typahead/bootstrap3-typeahead.min.js"></script>
<script type="text/javascript" src="js/i18n.js"></script>
<script type="text/javascript" src="js/main.js"></script>
<script>
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
Expand Down
114 changes: 114 additions & 0 deletions js/i18n.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
var i18n = {
currentLang: 'en',
messages: {},

init: function() {
var savedLang = localStorage.getItem('lang');
if (savedLang && (savedLang === 'en' || savedLang === 'zh')) {
this.currentLang = savedLang;
} else {
var browserLang = navigator.language || navigator.userLanguage;
this.currentLang = browserLang.startsWith('zh') ? 'zh' : 'en';
localStorage.setItem('lang', this.currentLang);
}

this.loadMessages();
},

loadMessages: function() {
var en = {
'title': 'Github Release Stats',
'description': 'Get the latest release stats like download counts, release dates, author on any Github project',
'keywords': 'Github, release, download, count',
'toggleNav': 'Toggle navigation',
'viewOnGithub': 'View project on Github',
'enterProjectDetails': 'Enter project details...',
'githubUsername': 'Github username',
'repositoryName': 'Repository name',
'getStats': 'Get the latest release stats!',
'statsDescription': '...and get the latest release stats like download counts, release dates, authors for any Github project.',
'releaseStats': 'release stats',
'newer': 'Newer',
'older': 'Older',
'perPage': 'Per page',
'downloadInfo': 'Download Info',
'releaseInfo': 'Release Info',
'author': 'Author',
'published': 'Published',
'downloads': 'Downloads',
'totalDownloads': 'Total Downloads',
'latestRelease': 'Latest release',
'preRelease': 'Pre-release',
'projectNotExist': 'The project does not exist!',
'rateLimitExceeded': "You've exceeded GitHub's rate limiting.<br />Please try again in about an hour.",
'noMoreReleases': 'No more releases',
'noReleases': 'There are no releases for this project',
'lastUpdated': 'Last updated on',
'times': 'times',
'mib': 'MiB',
'language': 'Language',
'chinese': '中文',
'english': 'English',
'titleDescription': 'release stats'
};

var zh = {
'title': 'Github 发布统计',
'description': '获取任何 Github 项目的最新发布统计信息,如下载次数、发布日期、作者等',
'keywords': 'Github, 发布, 下载, 统计',
'toggleNav': '切换导航',
'viewOnGithub': '在 Github 上查看项目',
'enterProjectDetails': '输入项目信息...',
'githubUsername': 'Github 用户名',
'repositoryName': '项目名称',
'getStats': '获取最新发布统计!',
'statsDescription': '...获取任何 Github 项目的最新发布统计信息,如下载次数、发布日期、作者等。',
'releaseStats': '发布统计',
'newer': '较新',
'older': '较旧',
'perPage': '每页显示',
'downloadInfo': '下载信息',
'releaseInfo': '发布信息',
'author': '作者',
'published': '发布于',
'downloads': '下载次数',
'totalDownloads': '总下载次数',
'latestRelease': '最新发布',
'preRelease': '预发布',
'projectNotExist': '该项目不存在!',
'rateLimitExceeded': '您已超过 GitHub 的速率限制。<br />请在大约一小时后重试。',
'noMoreReleases': '没有更多发布版本',
'noReleases': '该项目没有发布版本',
'lastUpdated': '最后更新于',
'times': '次',
'mib': 'MiB',
'language': '语言',
'chinese': '中文',
'english': 'English',
'titleDescription': '发布统计'
};

this.messages = {
'en': en,
'zh': zh
};
},

t: function(key) {
var msg = this.messages[this.currentLang];
return msg && msg[key] ? msg[key] : this.messages['en'][key] || key;
},

setLang: function(lang) {
if (lang === 'en' || lang === 'zh') {
this.currentLang = lang;
localStorage.setItem('lang', lang);
}
},

getLang: function() {
return this.currentLang;
}
};

i18n.init();
66 changes: 52 additions & 14 deletions js/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,41 @@
var apiRoot = "https://api.github.com/";

function updateUIText() {
document.title = i18n.t('title');
document.getElementById('page-title').textContent = i18n.t('title');
document.getElementById('page-description').content = i18n.t('description');
document.getElementById('page-keywords').content = i18n.t('keywords');
document.getElementById('navbar-title').textContent = i18n.t('title');
document.getElementById('lang-display').textContent = i18n.t('language');
document.getElementById('view-github').textContent = i18n.t('viewOnGithub');
document.getElementById('enter-details').textContent = i18n.t('enterProjectDetails');
document.getElementById('get-stats-button').textContent = i18n.t('getStats');
document.getElementById('desc-text').textContent = i18n.t('statsDescription');
document.getElementById('get-prev-results-button').textContent = i18n.t('newer');
document.getElementById('get-next-results-button').textContent = i18n.t('older');
document.getElementById('per-page-label').textContent = i18n.t('perPage');

document.getElementById('username').placeholder = i18n.t('githubUsername');
document.getElementById('repository').placeholder = i18n.t('repositoryName');

var titleDesc = document.getElementById('title-description');
if (titleDesc) {
titleDesc.textContent = i18n.t('titleDescription');
}
}

function changeLang(lang) {
i18n.setLang(lang);
updateUIText();
var username = getQueryVariable("username");
var repository = getQueryVariable("repository");
if(username != "" && repository != "") {
var page = getQueryVariable("page") || 1;
var perPage = getQueryVariable("per_page") || 5;
getStats(page, perPage);
}
}

// Return a HTTP query variable
function getQueryVariable(variable) {
var query = window.location.search.substring(1);
Expand Down Expand Up @@ -67,17 +103,17 @@ function showStats(data) {

if(data.status == 404) {
err = true;
errMessage = "The project does not exist!";
errMessage = i18n.t('projectNotExist');
}

if(data.status == 403) {
err = true;
errMessage = "You've exceeded GitHub's rate limiting.<br />Please try again in about an hour.";
errMessage = i18n.t('rateLimitExceeded');
}

if(data.length == 0) {
err = true;
errMessage = getQueryVariable("page") > 1 ? "No more releases" : "There are no releases for this project";
errMessage = getQueryVariable("page") > 1 ? i18n.t('noMoreReleases') : i18n.t('noReleases');
}

var html = "";
Expand All @@ -101,28 +137,28 @@ function showStats(data) {
var publishDate = item.published_at.split("T")[0];

if(isPreRelease) {
releaseBadge = "&nbsp;&nbsp;<span class='badge'>Pre-release</span>";
releaseBadge = "&nbsp;&nbsp;<span class='badge'>" + i18n.t('preRelease') + "</span>";
releaseClassNames += " pre-release";
} else if(isLatestRelease) {
releaseBadge = "&nbsp;&nbsp;<span class='badge'>Latest release</span>";
releaseBadge = "&nbsp;&nbsp;<span class='badge'>" + i18n.t('latestRelease') + "</span>";
releaseClassNames += " latest-release";
isLatestRelease = false;
}

var downloadInfoHTML = "";
if(releaseAssets.length) {
downloadInfoHTML += "<h4><span class='glyphicon glyphicon-download'></span>&nbsp;&nbsp;" +
"Download Info</h4>";
i18n.t('downloadInfo') + "</h4>";

downloadInfoHTML += "<ul>";

$.each(releaseAssets, function(index, asset) {
var assetSize = (asset.size / 1048576.0).toFixed(2);
var lastUpdate = asset.updated_at.split("T")[0];

downloadInfoHTML += "<li><code>" + asset.name + "</code> (" + assetSize + "&nbsp;MiB) - " +
"downloaded " + formatNumber(asset.download_count) + "&nbsp;times. " +
"Last&nbsp;updated&nbsp;on&nbsp;" + lastUpdate + "</li>";
downloadInfoHTML += "<li><code>" + asset.name + "</code> (" + assetSize + "&nbsp;" + i18n.t('mib') + ") - " +
i18n.t('downloads') + "&nbsp;" + formatNumber(asset.download_count) + "&nbsp;" + i18n.t('times') + ". " +
i18n.t('lastUpdated') + "&nbsp;" + lastUpdate + "</li>";

totalDownloadCount += asset.download_count;
releaseDownloadCount += asset.download_count;
Expand All @@ -136,21 +172,21 @@ function showStats(data) {
releaseBadge + "</h3>" + "<hr class='release-hr'>";

html += "<h4><span class='glyphicon glyphicon-info-sign'></span>&nbsp;&nbsp;" +
"Release Info</h4>";
i18n.t('releaseInfo') + "</h4>";

html += "<ul>";

if (releaseAuthor) {
html += "<li><span class='glyphicon glyphicon-user'></span>&nbsp;&nbsp;" +
"Author: <a href='" + releaseAuthor.html_url + "'>@" + releaseAuthor.login +"</a></li>";
i18n.t('author') + ": <a href='" + releaseAuthor.html_url + "'>@" + releaseAuthor.login +"</a></li>";
}

html += "<li><span class='glyphicon glyphicon-calendar'></span>&nbsp;&nbsp;" +
"Published: " + publishDate + "</li>";
i18n.t('published') + ": " + publishDate + "</li>";

if(releaseDownloadCount) {
html += "<li><span class='glyphicon glyphicon-download'></span>&nbsp;&nbsp;" +
"Downloads: " + formatNumber(releaseDownloadCount) + "</li>";
i18n.t('downloads') + ": " + formatNumber(releaseDownloadCount) + "</li>";
}

html += "</ul>";
Expand All @@ -162,7 +198,7 @@ function showStats(data) {

if(totalDownloadCount) {
var totalHTML = "<div class='row total-downloads'>";
totalHTML += "<h1><span class='glyphicon glyphicon-download'></span>&nbsp;&nbsp;Total Downloads</h1>";
totalHTML += "<h1><span class='glyphicon glyphicon-download'></span>&nbsp;&nbsp;" + i18n.t('totalDownloads') + "</h1>";
totalHTML += "<span>" + formatNumber(totalDownloadCount) + "</span>";
totalHTML += "</div>";

Expand Down Expand Up @@ -199,6 +235,8 @@ function redirect(page, perPage) {

// The main function
$(function() {
updateUIText();

$("#loader-gif").hide();

validateInput();
Expand Down