aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLibravatar Renard 2019-04-10 00:35:45 -0400
committerLibravatar Renard 2019-04-10 00:35:45 -0400
commitff5c78c312ac1f043835415bca210a072e8551d6 (patch)
tree651c8b2396e56c51fe0499381bd90ad46f330555
parenta712b03d4edf829eaaca66ed297cdba6563bc524 (diff)
downloadweabot-ff5c78c312ac1f043835415bca210a072e8551d6.tar.gz
weabot-ff5c78c312ac1f043835415bca210a072e8551d6.tar.xz
weabot-ff5c78c312ac1f043835415bca210a072e8551d6.zip
Fix: TamaƱos de archivo legibles
-rw-r--r--static/js/weabot.js24
1 files changed, 24 insertions, 0 deletions
diff --git a/static/js/weabot.js b/static/js/weabot.js
index 5a92836..f063735 100644
--- a/static/js/weabot.js
+++ b/static/js/weabot.js
@@ -332,6 +332,29 @@ function applyTheme(){
set_stylesheet(newTheme);
}
+function humanFileSize(bytes) {
+ var thresh = 1024;
+ if(Math.abs(bytes) < thresh) {
+ return bytes + ' B';
+ }
+ var units = ['kB','MB','GB'];
+ var u = -1;
+ do {
+ bytes /= thresh;
+ ++u;
+ } while(Math.abs(bytes) >= thresh && u < units.length - 1);
+ return bytes.toFixed(1)+' '+units[u];
+}
+
+function fixFileSize(){
+ var obj = document.getElementsByClassName("fs");
+ for (var i = 0; i < obj.length; i++){
+ var parts = obj[i].childNodes[2].textContent.split(" B, ");
+ var filesize = parts[0].substring(2);
+ obj[i].childNodes[2].textContent = " (" + humanFileSize(filesize) + ", " + parts[1];
+ }
+}
+
document.addEventListener("DOMContentLoaded", function(e) {
checkhighlight();
if (localStorage.hasOwnProperty("weabot")) weabot = JSON.parse(localStorage.getItem("weabot"));
@@ -376,6 +399,7 @@ document.addEventListener("DOMContentLoaded", function(e) {
types = document.getElementById("filetypes").innerText.split(", ");
if (types.includes("JPG")) types.push("JPEG");
postform.file.addEventListener("change", filePreview);
+ fixFileSize();
}
var del = document.getElementById("delform");