realized i don't need JS speedrate()

This commit is contained in:
iou1name 2019-02-16 15:31:44 -05:00
parent 98461c808f
commit e013d79e6e

View File

@ -11,24 +11,10 @@ function get_active_torrents() {
torrents = JSON.parse(httpRequest.responseText); torrents = JSON.parse(httpRequest.responseText);
let html_str = ''; let html_str = '';
for (let i = 0; i < torrents.length; i++) { for (let i = 0; i < torrents.length; i++) {
html_str += '<tr><td class="name">' + torrents[i].name + '</td><td class="state">' + torrents[i].state + '</td><td class="downrate">' + speedrate(torrents[i].downrate) + '</td><td class="uprate">' + speedrate(torrents[i].uprate) + '</td><td class="tracker">' + torrents[i].tracker + "</td>"; html_str += '<tr><td class="name">' + torrents[i].name + '</td><td class="state">' + torrents[i].state + '</td><td class="downrate">' + torrents[i].downrate_str + '</td><td class="uprate">' + torrents[i].uprate_str + '</td><td class="tracker">' + torrents[i].tracker + "</td>";
} }
document.getElementById('torrents').children[1].innerHTML = html_str; document.getElementById('torrents').children[1].innerHTML = html_str;
}; };
httpRequest.open('GET', get_torrents_uri, true); httpRequest.open('GET', get_torrents_uri, true);
httpRequest.send(); httpRequest.send();
} }
function speedrate(rate) {
let unit = 'B/s';
if (rate > 1024) {
rate /= 1024;
unit = 'KiB/s';
}
if (rate > 1024) {
rate /= 1024;
unit = 'MiB/s';
}
rate = Math.round(rate*10)/10; // different from Python's round()
return rate + unit;
}