aboutsummaryrefslogtreecommitdiff
path: root/static/js/weabot.js
diff options
context:
space:
mode:
Diffstat (limited to 'static/js/weabot.js')
-rw-r--r--static/js/weabot.js22
1 files changed, 22 insertions, 0 deletions
diff --git a/static/js/weabot.js b/static/js/weabot.js
index 45b7063..428375a 100644
--- a/static/js/weabot.js
+++ b/static/js/weabot.js
@@ -332,6 +332,27 @@ function applyTheme() {
set_stylesheet(newTheme);
}
+function readableSize(B) {
+ var thresh = 1024;
+ if(Math.abs(B) < thresh) return B + " B";
+ var units = ["KB","MB","GB"];
+ var u = -1;
+ do {
+ B /= thresh;
+ ++u;
+ } while(Math.abs(B) >= thresh && u < units.length - 1);
+ return B.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 = "-(" + readableSize(filesize) + ", " + parts[1];
+ }
+}
+
document.addEventListener("DOMContentLoaded", function(e) {
checkhighlight();
if (localStorage.hasOwnProperty("weabot")) weabot = JSON.parse(localStorage.getItem("weabot"));
@@ -393,6 +414,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");