-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpopup.js
405 lines (319 loc) · 9.6 KB
/
popup.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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
var URL = "";
var allSites;
var corAuth;
var testNewSite = 0;
var TITLE = "loading";
var TEXT = "loading";
var WORDS = [];
var FIRSTTHREE= "";
var AUTHOR = "not applicable";
var AUTHORLINK = "loading"
var checkWords = ["is","are","was","were","been","seem","seems","like","being","be"]
var topAdj = [];
var nounPair = [];
var sortedNouns = []
var authorFor = false;
var comments;
var spec;
var myData = []
var specBias = ""
var curCom = [];
var NAMES;
chrome.storage.sync.get('allSites', function(data) {
allSites = data.allSites;
});
chrome.storage.sync.get('corAuth', function(data) {
corAuth = data.corAuth;
});
chrome.storage.sync.get('comments', function(data) {
comments = data.comments;
});
chrome.storage.sync.get('spec', function(data) {
spec = data.spec;
});
let saveButton = document.getElementById('saveButton');
let saveButton2 = document.getElementById('saveButton2');
let btn = document.getElementById('btn');
$(function() {
chrome.tabs.query({active: true, 'windowId': chrome.windows.WINDOW_ID_CURRENT}, function(tabs) {
URL+= tabs[0].url;
for(var i = 0; i < allSites.length; i++){
if(allSites[i].URL == URL){
testNewSite += 1
displayInfo()
console.log("pre-loaded")
break;
}
}
if(allSites.length>0){
var name = allSites[allSites.length-1].AUTH.split(" ")
var name1 = name[0]
var name2 = name[1]
if((URL.includes(name1))||(URL.includes(name2))){
authorFor = true;
}
}
var already = false;
for(var a = 0; a < spec.length; a++){
if(spec[a].URL == URL){
var specAvg = 0;
for(var i = 0; i < spec[a].SPECDATA.length; i ++){
specAvg += parseInt(spec[a].SPECDATA[i]);
already = true;
}
console.log(specAvg)
specAvg/=(spec[a].SPECDATA.length - 1)
document.getElementById("myRange").value = specAvg;
console.log(specAvg)
if(specAvg < 20){
document.getElementById('how').innerHTML = "people think that this article has a far left bias"
}
else if((specAvg >= 20)&&(specAvg < 40)){
document.getElementById('how').innerHTML = "people think that this article has a moderate left bias"
}
else if((specAvg >= 40)&&(specAvg < 60)){
document.getElementById('how').innerHTML = "people think that this article has a moderate bias"
}
else if((specAvg >= 60)&&(specAvg < 80)){
document.getElementById('how').innerHTML = "people think that this article has a moderate right bias"
}
else{
document.getElementById('how').innerHTML = "people think that this article has a far right bias"
}
}
}
if(already == false){
document.getElementById('how').innerHTML = "no one has voted on this article yet. be the first!"
}
if(testNewSite == 0){
//sent to content to get title
$(function() {
chrome.tabs.query({active: true, 'windowId': chrome.windows.WINDOW_ID_CURRENT}, function(tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {"message": "fetch_title"});
});
});
//send to content to get para
$(function() {
chrome.tabs.query({active: true, 'windowId': chrome.windows.WINDOW_ID_CURRENT}, function(tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {"message": "fetch_para"});
});
});
}
});
});
saveButton.onclick = function(element) {
let userinput = select('#userinput');
let ui = userinput.value();
let username = select('#username')
let um = username.value();
comments.push(addComment(URL, um, ui));
chrome.storage.sync.set({comments});
createP("username: " + um + " " + "comment: " + ui)
}
btn.onclick = function(element) {
for(var i = 0; i < allSites.length; i++){
if(allSites[i].URL == URL){
console.log(allSites[i].AUTHURL)
window.open(allSites[i].AUTHURL)
}
}
}
saveButton2.onclick = function(element) {
let myRange = select('#myRange');
var done = false;
for(var i = 0; i < spec.length; i++){
if(spec[i].URL == URL){
spec[i].SPECDATA.push(myRange.value())
done = true;
console.log(spec[i].SPECDATA)
}
}
if(done == false){
myData.push(myRange.value());
spec.push(createSpectrum(URL,myData))
console.log(spec[spec.length-1])
}
chrome.storage.sync.set({spec});
}
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "works_fetched" ) {
corAuth.push(saveAuthor(allSites[allSites.length-1].URL,request.data));
chrome.storage.sync.set({corAuth});
console.log(request.data);
console.log(corAuth[0].PASTURL)
}
}
);
//once get para from content
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "para_fetched" ) {
var LINETEXT=request.data;
for(var i = 0; i < LINETEXT.length; i++){
TEXT+= LINETEXT[i];
TEXT+= " ";
}
//split at each space or enter so that individual words
var WORDS = TEXT.split(" ");
console.log(WORDS)
//parameters for rita.js
var params = {
ignoreStopWords: true,
ignoreCase: true,
ignorePunctuation: true
};
//without stop words
var noStop = RiTa.concordance(LINETEXT.join(" "), params);
var allWords = [];
for (var i in noStop) {
allWords.push(i);
}
for (var i = 1; i < allWords.length-1; i++) {
if((RiTa.isAdjective(allWords[i]))&&(RiTa.isVerb(allWords[i])==false)){
topAdj.push(allWords[i])
if(RiTa.isNoun(allWords[i+1])){
nounPair.push(allWords[i+1])
}
else if(RiTa.isNoun(allWords[i-1])){
nounPair.push(allWords[i-1])
}
else{
loop1:
for(var b = 1; b < 5; b++){
loop2:
for(var a = 0; a < checkWords.length; a++){
if(allWords[i-b]==checkWords[a]){
loop3:
for(var c = 0; c < 5; c++){
if(RiTa.isNoun(allWords[i-b-c])){
nounPair.push(allWords[i-b-c])
break loop1;
}
}
}
}
}
if(nounPair.length<topAdj.length){
nounPair.push("NO NOUN ")
}
}
}
}
for(var y = 0; y < nounPair.length; y ++){
if (nounPair[y] !== "NO NOUN "){
sortedNouns.push(nounPair[y])
}
}
//
sortedNouns.sort(compare2)
function compare2(a, b) {
return (noStop[b] - noStop[a])
}
for(var i = 0; i<LINETEXT.length - 2; i++ ){
if((LINETEXT[i][0]==="B")&&((LINETEXT[i][1]==="y")||(LINETEXT[i][1]==="Y"))&&(LINETEXT[i][2]===" ")){
AUTHOR = "";
for(var a = 3; a < LINETEXT[i].length; a++){
AUTHOR+=LINETEXT[i][a];
}
}
//break;
}
/*NAMES = AUTHOR.toLowerCase().split(" ")
console.log(NAMES)
if((URL.includes(NAMES[0]))||(URL.includes(NAMES[0]))){
authorFor = true;
}*/
$(function() {
chrome.tabs.query({active: true, 'windowId': chrome.windows.WINDOW_ID_CURRENT}, function(tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {"message": "fetch_hyper"});
});
});
}
}
);
//once get title from content
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "title_fetched" ) {
TITLE = request.data;
}
}
);
chrome.runtime.onMessage.addListener(
function(request, sender, sendResponse) {
if( request.message === "hyper_fetched" ) {
NAMES = AUTHOR.toLowerCase().split(" ")
console.log(NAMES)
console.log(AUTHOR)
console.log(authorFor)
if(authorFor == false){
HYPER = request.data;
for(var x = 0; x < HYPER.length; x++){
if(HYPER[x].includes(NAMES[0])){
AUTHORLINK = HYPER[x]
}
else if (HYPER[x].includes(NAMES[1])){
AUTHORLINK = HYPER[x]
}
}
console.log(AUTHORLINK)
allSites.push(storeWebsite(URL, TITLE, topAdj, sortedNouns, nounPair, AUTHOR, AUTHORLINK));
chrome.storage.sync.set({allSites});
testNewSite += 1
displayInfo()
console.log("notauth")
}
else if (authorFor == true){
document.body.innerHTML = "";
createP("downloading info about author. return to article to see it!")
$(function() {
chrome.tabs.query({active: true, 'windowId': chrome.windows.WINDOW_ID_CURRENT}, function(tabs) {
var activeTab = tabs[0];
chrome.tabs.sendMessage(activeTab.id, {"message": "fetch_works"});
});
});
console.log("auth")
}
}
}
);
function draw(){
createCanvas(350, 0);
}
function displayInfo(){
for(var i = 0; i < allSites.length; i++){
if(allSites[i].URL == URL){
document.getElementById('tit').innerHTML = "TITLE: " + allSites[i].TITLE
document.getElementById('aut').innerHTML = "AUTHOR: " + allSites[i].AUTH
var pair1 = allSites[i].PAIR;
var sort1 = allSites[i].SORT;
var adj1 = allSites[i].ADJ;
for(var x = 0; x < 5; x ++){
for(var y = 0; y < pair1.length; y++){
if(sort1[x] == pair1[y]){
var num = (x+1).toString()
document.getElementById(num).innerHTML = sort1[x] +" / " + adj1[y]
}
}
}
}
}
for(var b = 0; b < comments.length; b++){
if(comments[b].URL == URL){
createP("username: " + comments[b].NAME + "comment: " + comments[b].COM)
console.log(comments[b].COM)
}
}
for(var a = 0; a < corAuth.length; a++){
if(corAuth[a].PASTURL == URL){
document.getElementById('works').innerHTML = "this author wrote articles titled: "
document.getElementById('works1').innerHTML =(corAuth[a].AUTHORWORKS[1])
document.getElementById('works2').innerHTML =(corAuth[a].AUTHORWORKS[2])
document.getElementById('works3').innerHTML =(corAuth[a].AUTHORWORKS[3])
}
}
}