| 4 | | function xhttp (opts) { |
| 5 | | var d = Deferred(); |
| 6 | | if (opts.onload) d = d.next(opts.onload); |
| 7 | | if (opts.onerror) d = d.error(opts.onerror); |
| 8 | | opts.onload = function (res) { |
| 9 | | d.call(res); |
| 10 | | }; |
| 11 | | opts.onerror = function (res) { |
| 12 | | d.fail(res); |
| 13 | | }; |
| 14 | | GM_xmlhttpRequest(opts); |
| 15 | | return d; |
| 16 | | } |
| 17 | | xhttp.get = function (url) { return xhttp({method:"get", url:url}) } |
| 18 | | xhttp.post = function (url, data) { return xhttp({method:"post", url:url, data:data}) } |
| 19 | | |
| 20 | | function http (opts) { |
| 21 | | var d = Deferred(); |
| 22 | | var req = new XMLHttpRequest(); |
| 23 | | req.open(opts.method, opts.url, true); |
| 24 | | req.onreadystatechange = function () { |
| 25 | | if (req.readyState == 4) d.call(req); |
| 26 | | }; |
| 27 | | req.send(opts.data || null); |
| 28 | | return d; |
| 29 | | } |
| 30 | | http.get = function (url) { return http({method:"get", url:url}) } |
| 31 | | http.post = function (url, data) { return http({method:"post", url:url, data:data}) } |
| 32 | | |
| | 167 | function xhttp (opts) { |
| | 168 | var d = Deferred(); |
| | 169 | if (opts.onload) d = d.next(opts.onload); |
| | 170 | if (opts.onerror) d = d.error(opts.onerror); |
| | 171 | opts.onload = function (res) { |
| | 172 | d.call(res); |
| | 173 | }; |
| | 174 | opts.onerror = function (res) { |
| | 175 | d.fail(res); |
| | 176 | }; |
| | 177 | GM_xmlhttpRequest(opts); |
| | 178 | return d; |
| | 179 | } |
| | 180 | xhttp.get = function (url) { return xhttp({method:"get", url:url}) } |
| | 181 | xhttp.post = function (url, data) { return xhttp({method:"post", url:url, data:data}) } |
| | 182 | |
| | 183 | function http (opts) { |
| | 184 | var d = Deferred(); |
| | 185 | var req = new XMLHttpRequest(); |
| | 186 | req.open(opts.method, opts.url, true); |
| | 187 | req.onreadystatechange = function () { |
| | 188 | if (req.readyState == 4) d.call(req); |
| | 189 | }; |
| | 190 | req.send(opts.data || null); |
| | 191 | return d; |
| | 192 | } |
| | 193 | http.get = function (url) { return http({method:"get", url:url}) } |
| | 194 | http.post = function (url, data) { return http({method:"post", url:url, data:data}) } |
| | 195 | |
| | 196 | Deferred.Deferred = Deferred; |
| | 197 | Deferred.http = http; |
| | 198 | Deferred.xhttp = xhttp; |