Skip to content

Commit 6ff8623

Browse files
authored
Fixed #1563, Added dynamic size
1. This patch fixes #1563 (invalid url for the `.7z` link set), by adding `break` after each appropriate `case`. 2. Also, while the url is fetched from the GitHub api, the byte size is also fetched. Using `getSizeInMb()`, the correct size is also set.
1 parent fa825de commit 6ff8623

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

index.html

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,15 +75,15 @@ <h3>Download</h3>
7575
<a id="mini" onclick="_gaq.push(['_trackEvent', 'Download', 'mini'])" href="https://github.com/cmderdev/cmder/releases/latest">
7676
<button class="gray">Download Mini</button>
7777
</a>
78-
<small>~7.8MB</small>
78+
<small is="mini-size">~7.8MB</small>
7979
</div>
8080
<div class="bit-2">
8181
<a id="full" onclick="_gaq.push(['_trackEvent', 'Download', 'full'])" href="https://github.com/cmderdev/cmder/releases/latest">
8282
<button class="blue">Download Full</button>
8383
</a>
84-
<small>(With Git for Windows) ~100MB</small>
84+
<small>(With Git for Windows) <span id="full-size">~100MB</span></small>
8585
<small>
86-
<em><a id="7z" onclick="_gaq.push(['_trackEvent', 'Download', 'full', '7z'])" href="https://github.com/cmderdev/cmder/releases/latest">~52MB 7z</a></em>
86+
<em><a id="7z" onclick="_gaq.push(['_trackEvent', 'Download', 'full', '7z'])" href="https://github.com/cmderdev/cmder/releases/latest"><span id="7z-size">~52MB</span> 7z</a></em>
8787
</small>
8888
</div>
8989

@@ -200,17 +200,29 @@ <h4>Other documentations</h4>
200200
$(document).ready(function () {
201201
getLatestReleases();
202202
})
203+
204+
function getSizeInMb( bytes, decimal ) {
205+
var decimal = decimal || 0;
206+
var size = (bytes / Math.pow(2, 20));
207+
return '~' + ( decimal == 0 ? Math.ceil(size) : size.toFixed(decimal) ) + 'MB';
208+
}
203209

204210
function getLatestReleases() {
205211
$.getJSON("https://api.github.com/repos/cmderdev/cmder/releases/latest").done(function (release) {
206212
for (const asset of release.assets) {
207213
switch (asset.name) {
208214
case "cmder.zip":
209215
$("#full").attr("href", asset.browser_download_url);
216+
$("#full-size").html( getSizeInMb(asset.size) );
217+
break;
210218
case "cmder_mini.zip":
211219
$("#mini").attr("href", asset.browser_download_url);
220+
$("#mini-size").html( getSizeInMb(asset.size, 1) );
221+
break;
212222
case "cmder.7z":
213223
$("#7z").attr("href", asset.browser_download_url);
224+
$("#7z-size").html( getSizeInMb(asset.size) );
225+
break;
214226
}
215227
}
216228
})

0 commit comments

Comments
 (0)