forked from devcnn88/MHAutoBotEnhanced
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
58 lines (56 loc) · 1.41 KB
/
background.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
51
52
53
54
55
56
57
58
var mapPort;
chrome.runtime.onConnect.addListener(function(port) {
if(port.name == 'map'){
mapPort = port;
mapPort.onMessage.addListener(function(msg) {
console.log(msg);
if (msg.request == "getUncaught"){
ajaxPost(msg.url, msg.data, function (data){
console.log(data.treasure_map);
if(data.treasure_map.groups !== null && data.treasure_map.groups !== undefined){
var arrUncaught = [];
for(var i=0;i<data.treasure_map.groups.length;i++){
if(data.treasure_map.groups[i].is_uncaught === true){
for(var j=0;j<data.treasure_map.groups[i].mice.length;j++){
arrUncaught.push(data.treasure_map.groups[i].mice[j].name);
}
}
}
mapPort.postMessage({
obj : msg.objMapHunting,
array : arrUncaught
});
}
}, function (error){
console.error('mapPort ajax:',error);
mapPort.postMessage([]);
});
}
else if(msg.request == "discard"){
ajaxPost(msg.url, msg.data, function (data){
}, function (error){
console.error('mapPort ajax:',error);
});
}
});
}
});
function ajaxPost(postURL, objData, callback, throwerror){
try {
jQuery.ajax({
type: 'POST',
url: postURL,
data: objData,
contentType: 'application/x-www-form-urlencoded',
dataType: 'json',
xhrFields: {
withCredentials: false
},
success: callback,
error: throwerror,
});
}
catch (e) {
throwerror();
}
}