var gif, img var imageURL = null function loadImage(imageURL, callback) { var imageURL = proxify( imageURL ); window.imageURL = imageURL window.gif = window.img = window.cam = null if (! imageURL) { window.gif = null window.img = null callback() } else if (imageURL.substr(-3).toLowerCase() === "gif") { window.gif = GIF(imageURL); // gif.on("error", tryToLoadNextImage); // gif.on("rendered", trackLoadTime); gif.on("rendered", callback); gif.render(); } else { window.img = new Image(); // img.addEventListener("error", tryToLoadNextImage); img.addEventListener("load", callback); img.crossOrigin = "anonymous"; img.src = imageURL; } } function giveImage(t) { if (window.gif) { return gif.frames[gif.currentFrame(t)]; } else { return img; } } function proxify (url) { if (url.indexOf("http") == 0) return "/cgi-bin/proxy?" + url.replace(/^https/, "http"); else return url } function filesize(n) { if (n < 1e3) return n + " bytes" if (n < 1e6) return decimalString(n/1e3) + " kb" if (n < 1e9) return decimalString(n/1e6) + " mb" return "WAY TOO BIG DUDE" } function decimalString(n){ var m = Math.floor(n); return m + "." + Math.round((n-m)*10) } function noop(){} function uploadImage(opt){ if (! opt.blob || ! opt.filename) return; opt.username = opt.username || ""; opt.success = opt.success || noop; opt.error = opt.error || noop; var form = new FormData(); form.append("username", opt.username); form.append("filename", opt.filename); form.append("qqfile", opt.blob); form.append("tag", opt.tag); var req = new XMLHttpRequest(); req.open("POST", "/cgi-bin/im/shader/upload"); req.onload = function(event) { if (req.status == 200) { var res = JSON.parse(req.responseText); if (res.success) { opt.success(res); } else { opt.error(res); } } else { opt.error({ success: false, error: req.status }); } }; req.send(form); }