-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
57 lines (48 loc) · 1.55 KB
/
content.js
File metadata and controls
57 lines (48 loc) · 1.55 KB
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
49
50
51
52
53
54
55
56
setTimeout(function() {
if (window.location.href.indexOf("watch") > -1) {
//while (document.querySelectorAll("yt-formatted-string#content-text")[i].innerHTML
for (let commentItem of document.querySelectorAll("yt-formatted-string#content-text")){
console.log(commentItem);
let data = commentItem.innerHTML;
console.log(data);
// let fetchData = {
// body: "docum
// headers: new Headers()
// };
const url = 'http://localhost:3000/api/add/comment';
let comment = {
john: data
}
// The parameters we are gonna pass to the fetch function
let fetchData = {
method: 'POST',
body: JSON.stringify(comment),
headers: {
'Content-Type': 'application/json'
}
}
var replacements = ["Wow Great Video! :)", "This is a positive comment :D", "Live, laugh, love <3", "You are amazing","Keep it up!"];
var textVal = 0;
fetch(url, fetchData) // Call the fetch function passing the url of the API as a parameter
.then(function(res) {
return res.json();
}).then((myJson) => {
console.log(data);
console.log(myJson);
console.log(myJson.message);
if (myJson.message == "bad") {
commentItem.style.color = "limegreen";
commentItem.style.bold = "true";
commentItem.textContent = replacements[textVal];
textVal++;
}
})
.catch(function() {
// This is where you run code if the server returns any errors
});
// if (data) {
// commentItem.style.color = "white";
// }
}
}
},10000);