Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Made from scratch based on https://github.com/ShiftSpace/gmrequest/blob/master/GMRequest.js
- XMLHttpRequest = function () {
- var _params = {
- context : this,
- headers : {},
- onreadystatechange : function (detail) {
- this.status = detail.status;
- this.statusText = detail.statusText;
- this.responseHeaders = detail.responseHeaders;
- this.responseText = detail.responseText;
- this.readyState = detail.readyState;
- this.onreadystatechange && this.onreadystatechange();
- }.bind(this),
- },
- _exec,
- _send = function (data, binary) {
- var t = {
- data : data,
- binary : binary,
- };
- for (var key in _params) {
- t[key] = _params[key];
- }
- for (var key in this) {
- if (!(key in t)) {
- if (this[key] instanceof Function) {
- t[key] = function (xhr) {
- this[key].call(this, xhr);
- }.bind(this);
- } else {
- t[key] = this[key];
- }
- }
- }
- _exec = GM_xmlhttpRequest(t);
- }.bind(this);
- this.setRequestHeader = function (key, value) {
- _params.headers[key] = value;
- };
- this.getResponseHeader = function (key) {
- return this.responseHeaders[key];
- };
- this.getAllResponseHeaders = function () {
- return this.responseHeaders;
- };
- this.overrideMimeType = function (value) {
- _params.overrideMimeType = value;
- };
- this.open = function (_method, _url, _async, _user, _passw) {
- this.abort();
- _params.method = _method.toUpperCase();
- _params.url = _url;
- _params.synchronous = !_async;
- _params.user = _user;
- _params.password = _passw;
- };
- this.abort = function () {
- _exec && _exec.abort();
- }
- this.send = function (data) {
- _send(data, false);
- };
- this.sendAsBinary = function (data) {
- _send(data, true);
- }
- };
Advertisement
Add Comment
Please, Sign In to add comment