-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathbackground.js
More file actions
55 lines (42 loc) · 1.56 KB
/
Copy pathbackground.js
File metadata and controls
55 lines (42 loc) · 1.56 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
var uselessWords = ["is","of","the","on","off","was","i","","has","have","had","will","a","in","that","it","an","its","and","by","be","."," "]
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
console.log(sender.tab ?
"from a content script:" + sender.tab.url :
"from the extension");
var wordArray=request.words.split(/\r\n|\n|\r/);
var scoresArray=request.score.split(/\r\n|\n|\r/);
var htmlWords=($("body").text().split(/\s+/));
var arrToLow = String.prototype.toLowerCase.apply(htmlWords).split(",");
var diff = $(arrToLow).not(uselessWords).get();
var value = 0;
var count=0;
var happyCount=0,sadCount=0;
var k=0;
for (var i = 0; i < wordArray.length; i++) {
for (var j =0; j < diff.length-1; j++) {
if (diff[j]==wordArray[i]) {
value+=parseInt(scoresArray[i]);
count=count+1;
if (parseInt(scoresArray[i])>7) {
happyCount+=1;
}
else if (parseInt(scoresArray[i])<3.5) {
sadCount+=1;
}
}
}
k=i;
}
if(k==wordArray.length-1){
console.log(happyCount+" sad "+sadCount)
if(happyCount==0&&sadCount==0)
{
sendResponse({val:-1});
}
else
{
sendResponse({val: value/count});
}
}
});