-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.js
48 lines (41 loc) · 1.79 KB
/
main.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
// Upvoted answers: 3 and above
const upvotedAnswers = Array.from(document.getElementsByClassName('answer'));
upvotedAnswers.map((node) => node.style.backgroundColor = '#ddffdb');
// Middle answers: -2 to 2
const middleAnswers = Array.from(document.querySelectorAll("div[data-score='-2'], div[data-score='-1'], div[data-score='0'], div[data-score='1'], div[data-score='2']"))
middleAnswers.map((node) => node.style.backgroundColor = '#f9ffc4');
// Downvoted: -3 and below - default: red
const downvotedAnswers = Array.from(document.getElementsByClassName('downvoted-answer'));
downvotedAnswers.map((node) => { node.style.backgroundColor = '#ffbabc';
});
function dogify() {
console.log('dogify!')
// Downvoted: -3 and below
const downvotedAnswers = Array.from(document.getElementsByClassName('downvoted-answer'));
console.log(downvotedAnswers);
downvotedAnswers.map((node) => {
// Make get request to dog api!
fetch('https://dog.ceo/api/breed/pembroke/images/random')
.then((response) => response.json())
.then((JSONData) => {
node.style.backgroundColor = '';
node.innerText = '';
node.style.minHeight = 'auto'
let dog = document.createElement('img');
dog.src = `${JSONData.message}`
node.appendChild(dog)
})
.catch(error => console.log(error))
});
}
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 === "popupInit")
sendResponse({farewell: "goodbye"});
console.log('received from script');
dogify();
}
);