From 90533882ae77f811f01cc842fce9cab68df877ba Mon Sep 17 00:00:00 2001 From: Joe Robinson Date: Wed, 17 Aug 2016 15:13:29 +0100 Subject: Fixed receiving messages --- util.js | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 util.js (limited to 'util.js') diff --git a/util.js b/util.js new file mode 100644 index 0000000..a0bd718 --- /dev/null +++ b/util.js @@ -0,0 +1,31 @@ + +module.exports.imagify = function(url, channel) { + console.log(url); + $.ajax({ + type: 'HEAD', + url: url, + complete: function(xhr) { + var type = xhr.getResponseHeader('Content-Type') + var size = xhr.getResponseHeader('Content-Length'); + console.log(type); + console.log(size); + if (size < 10000000) { + $("[data-img='"+url+"']").append("("+humanize(size)+")"); + $("[data-img='"+url+"']").append("

"); + $("[data-img='"+url+"']").removeClass("loading"); + + } + + } + }); + + return "
"; + +} + +humanize = function(size) { + var units = ['bytes', 'kB', 'MB', 'GB', 'TB', 'PB']; + var ord = Math.floor(Math.log(size) / Math.log(1000)); + var s = Math.round((size / Math.pow(1000, ord)) * 100) / 100; + return s + ' ' + units[ord]; +} -- cgit v1.2.3