-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbakgrond.js
33 lines (29 loc) · 1.08 KB
/
bakgrond.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
function getSavedType(callback) {
chrome.storage.sync.get("methodtype", function (type) {
callback(type["methodtype"]);
});
}
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
var xhr = new XMLHttpRequest();
getSavedType(function(type){
var endpointrand;
if(type === "random")
endpointrand = elements[Math.floor(Math.random() * elements.length)];
else
endpointrand = type;
xhr.open("POST", "http://localhost:3000/" + endpointrand , true);
xhr.onload = function() {
if (xhr.readyState === xhr.DONE)
sendResponse(xhr.response.cookie);
};
xhr.onerror = function(reporse) {
console.log("Could not send message to translator", reporse);
};
xhr.setRequestHeader("Content-Type", "application/json;charset=UTF-8");
xhr.responseType = "json";
xhr.send(JSON.stringify({"cookie": request}));
});
return true;
}
);