-
Notifications
You must be signed in to change notification settings - Fork 0
/
content.js
113 lines (101 loc) · 3.12 KB
/
content.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
// chrome.runtime.sendMessage({todo:"showActionPage"});
window.addEventListener("load", (e) => {
chrome.storage.sync.set({ status: 0 });
});
var url;
async function getData() {
// const res=await fetch(urlOfJson)
// if(res.json()){
// chrome.runtime.sendMessage({todo:"msg9",message:"NOT Error"});
// }else{
// chrome.runtime.sendMessage({todo:"msg9",message:"Error"});
// }
// return (await fetch(urlOfJson)).json();
const location = window.location.hostname;
try {
const fetchResponse = await fetch("https://sentiment-analyzer-backend.herokuapp.com/", {
method: "POST",
headers: {
"Content-Type": "application/json",
},
body: JSON.stringify({
url: url,
}),
});
if (fetchResponse.ok) {
chrome.runtime.sendMessage({ todo: "msg9", message: "POST Request Successful" });
return fetchResponse.json();
} else {
chrome.runtime.sendMessage({ todo: "msg9", message: "Error" });
}
} catch (e) {
chrome.runtime.sendMessage({ todo: "msg9", message: JSON.stringify(e) });
}
}
chrome.runtime.onMessage.addListener(async (req, sender, sendRes) => {
if (req.todo == "hideComments") {
url = req.message;
chrome.runtime.sendMessage({ todo: "msg1" });
var hidden = [];
var data = await getData();
data.forEach((element) => {
if (element.value == 'Negative Comment') {
var c=element.comment;
c=c.replace(/\s+/g, '');
c=c.replace('\n','');
hidden.push(c);
}
});
// chrome.runtime.sendMessage({ todo: "msg4", message: hidden });
var msg;
var x = [];
var imgSrc = [];
var msgs = [];
var j = 0;
var p = 0;
var msgs1=[];
$("#contents")
.children()
.each((i) => {
msg = $("#content-text").text();
msgs1[j]=msg;
msg=msg.replace(/\s+/g, '');
msgs[j] = msg;
j++;
imgSrc[i] = $("#img").attr("src");
// imgSrc[i]=$('#content-text').text();
x[i] = $("#comment").parent().detach();
// chrome.runtime.sendMessage({todo:"count",count:i});
// chrome.runtime.sendMessage({todo:"msg4",message:msg});
});
// var j=0;
// setTimeout(()=>{
for (var i = x.length - 1; i >= 0; i--) {
// chrome.runtime.sendMessage({todo:"msg5",message:msg});
// chrome.runtime.sendMessage({todo:"msg6",message:imgSrc[j]});
// j++;
// if(imgSrc[i]=='https://yt3.ggpht.com/ytc/AAUvwnjEt2U7ffjo_Lx4NcBRYVU3E9ocPD6UpHQ0Ow=s88-c-k-c0x00ffffff-no-rj'){
// chrome.runtime.sendMessage({todo:"msg7",message:true});
// }
// if (hidden.includes(i)) {
// chrome.runtime.sendMessage({ todo: "msg9", message: msgs[i] });
// continue;
// } else {
// p++;
// $("#contents").prepend(x[i]);
// }
if(hidden.includes(msgs[i])){
chrome.runtime.sendMessage({ todo: "msg6",message:msgs1[i] });
// p--;
continue;
}else{
$("#contents").prepend(x[i]);
}
}
// }, 3000);
}
if (req.todo == "UnHideComments") {
chrome.runtime.sendMessage({ todo: "msg2" });
location.reload();
}
});