cleaned up some code

This commit is contained in:
Sriram Hariharan
2018-07-07 16:57:23 -05:00
parent 4d021c6d80
commit 8806e8d876
8 changed files with 68 additions and 43 deletions

View File

@@ -1,24 +1,19 @@
chrome.runtime.onMessage.addListener(function(request, sender, response) {
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
if (request.greeting == "hello")
sendResponse({ farewell: "goodbye" });
});
const xhr = new XMLHttpRequest();
const method = request.method ? request.method.toUpperCase() : "GET";
xhr.open(method, request.url, true);
xhr.onload = () => response(xhr.responseText);
xhr.onerror = () => response(xhr.statusText);
if (method == "POST") {
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}
xhr.send(request.data);
return true;
const xhr = new XMLHttpRequest();
const method = request.method ? request.method.toUpperCase() : "GET";
xhr.open(method, request.url, true);
xhr.onload = () => response(xhr.responseText);
xhr.onerror = () => response(xhr.statusText);
if (method == "POST") {
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
}
xhr.send(request.data);
return true;
});
chrome.runtime.onInstalled.addListener(function() {
chrome.storage.sync.set({color: '#3aa757'}, function() {
console.log("The color is green.");
});
});