-
Notifications
You must be signed in to change notification settings - Fork 0
/
xhr.js
50 lines (41 loc) · 1.48 KB
/
xhr.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
var fs = require("fs");
window.__nightmare = {};
__nightmare.ipc = require('electron').ipcRenderer;
window.epiData = fs.readFileSync("./test/module/epi.json");
window.epiData = JSON.parse(window.epiData);
window.epiDataCreateResponse = [];
window.confirm = function(message, defaultResponse){
return true;
}
var open = window.XMLHttpRequest.prototype.open;
window.currentResponse = [];
window.currentAction = undefined;
window.XMLHttpRequest.prototype.open = function (method, url, async, user, pass) {
this.addEventListener("readystatechange", function() {
if (this.readyState === 4) {
var responseJSON = { 'success': false };
try {
var responseJSON = JSON.parse(this.responseText);
if ( responseJSON && responseJSON.data && responseJSON.data.template ) {
delete responseJSON.data.template;
}
if ( responseJSON && responseJSON.data && responseJSON.data.template_left ) {
delete responseJSON.data.template_left;
}
if ( responseJSON && responseJSON.data && responseJSON.data.template_right ) {
delete responseJSON.data.template_right;
}
}
catch(e) {
}
if ( responseJSON && responseJSON.data && responseJSON.data.callback_success ) {
window.currentResponse[responseJSON.data.callback_success] = responseJSON;
}
}
}, false);
open.apply(this, arguments);
};
window.XMLHttpRequest.prototype.realSend = XMLHttpRequest.prototype.send;
window.XMLHttpRequest.prototype.send = function(vData) {
this.realSend(vData);
};