-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackground.js
39 lines (34 loc) · 1018 Bytes
/
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
let isDoggos = false;
chrome.runtime.onInstalled.addListener(() => {
chrome.storage.sync.set({isDoggos: false}, function() {
console.log('No newsworthy Doggos-- yet!');
});
});
chrome.runtime.onMessage.addListener((message, sender, sendResponse) => {
if (message = 'doggos') {
getDoggos(sendResponse);
}
return true;
});
function getDoggos(sendResponse) {
let url = "https://api.twitter.com/2/tweets/search/recent?query=from%3Adog_rates";
fetch(url, { method: "GET", headers:
{ "Accept": "application/json",
"Content-Type": "application/json; charset=utf-8" ,
"Authorization": "Bearer <TOKEN>"
}
}
).then(function(response) {
if (response.status !== 200) {
console.log('Looks like there was a problem. Status Code: ' +
response.status);
sendResponse(response);
return;
}
response.json().then(function(data) {
console.log('data', data);
sendResponse({data: data.data});
});
}
).catch(error => {console.log('Error:', error); sendResponse(error)});
}