Albirew/nyaa-pantsu
Archivé
1
0
Bifurcation 0

Update humanFileSize function

Cette révision appartient à :
MMP0 2017-06-03 00:21:08 +09:00 révisé par alucard0134
Parent a77e341585
révision 87117d08de

Voir le fichier

@ -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];
}
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";
}