diff --git a/public/js/torrents.js b/public/js/torrents.js index ca3e18df..7925e49a 100644 --- a/public/js/torrents.js +++ b/public/js/torrents.js @@ -38,20 +38,8 @@ document.addEventListener("DOMContentLoaded", function() { // if Torrents.CanRef } }) - -// Credits to mpen (StackOverflow) function humanFileSize(bytes, si) { - var thresh = si ? 1000 : 1024; - if(Math.abs(bytes) < thresh) { - return bytes + ' B'; - } - var units = si - ? ['kB','MB','GB','TB','PB','EB','ZB','YB'] - : ['KiB','MiB','GiB','TiB','PiB','EiB','ZiB','YiB']; - var u = -1; - do { - bytes /= thresh; - ++u; - } while(Math.abs(bytes) >= thresh && u < units.length - 1); - return bytes.toFixed(1)+' '+units[u]; -} \ No newline at end of file + var k = si ? 1000 : 1024; + var i = ~~(Math.log(bytes) / Math.log(k)); + return i == 0 ? bytes + " B" : (bytes / Math.pow(k, i)).toFixed(1) + " " + "KMGTPEZY"[i - 1] + (si ? "" : "i") + "B"; +}