-
Notifications
You must be signed in to change notification settings - Fork 5
/
background.js
32 lines (31 loc) · 1.16 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
chrome.browserAction.onClicked.addListener(function() {
chrome.tabs.create({
url: "popup.html"
});
});
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log("Got Message! " + request.contentScriptQuery);
if (request.contentScriptQuery == "queryAbout") {
var url = "https://www.reddit.com/user/" + request.user.name + "/about.json";
fetch(url)
.then(response => response.json())
.then(res => sendResponse({
'json': res,
'user': request.user
}))
.catch(error => console.log(error));
return true; // Will respond asynchronously.
} else if (request.contentScriptQuery == "queryComment") {
var url = request.url;
fetch(url)
.then(response => response.json())
.then(res => sendResponse({
'json': res,
'user': request.user,
'type': request.type
}))
.catch(error => console.log(error));
return true;
}
});