diff --git a/4chan_x.user.js b/4chan_x.user.js index eb6f816e0..477fb133f 100644 --- a/4chan_x.user.js +++ b/4chan_x.user.js @@ -310,6 +310,19 @@ id: function(id) { return d.getElementById(id); }, + formData: function(arg) { + var fd, key, val; + if (arg instanceof HTMLElement) { + fd = new FormData(arg); + } else { + fd = new FormData(); + for (key in arg) { + val = arg[key]; + fd.append(key, val); + } + } + return fd; + }, ajax: function(url, callbacks, opts) { var data, headers, key, r, type, upCallbacks, val; if (opts == null) { @@ -1979,7 +1992,7 @@ return QR.el.dispatchEvent(e); }, submit: function(e) { - var callbacks, captcha, captchas, challenge, data, err, m, name, opts, post, reply, response, threadID, val; + var callbacks, captcha, captchas, challenge, data, err, m, opts, post, reply, response, threadID; if (e != null) { e.preventDefault(); } @@ -2046,13 +2059,7 @@ recaptcha_challenge_field: challenge, recaptcha_response_field: response + ' ' }; - data = new FormData(); - for (name in post) { - val = post[name]; - if (val) { - data.append(name, val); - } - } + data = $.formData(post); callbacks = { onload: function() { return QR.response(this.response); diff --git a/script.coffee b/script.coffee index 003c05065..da202318b 100644 --- a/script.coffee +++ b/script.coffee @@ -265,6 +265,14 @@ $.extend $, cb JSON.parse e.newValue if e.key is "#{Main.namespace}#{key}" id: (id) -> d.getElementById id + formData: (arg) -> + if arg instanceof HTMLElement + fd = new FormData arg + else + fd = new FormData() + for key, val of arg + fd.append key, val + fd ajax: (url, callbacks, opts={}) -> {type, headers, upCallbacks, data} = opts r = new XMLHttpRequest() @@ -1548,9 +1556,7 @@ QR = recaptcha_challenge_field: challenge recaptcha_response_field: response + ' ' - data = new FormData() - for name, val of post - data.append name, val if val + data = $.formData post callbacks = onload: ->