forked from azk0019/CourseProject
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent.js
More file actions
83 lines (72 loc) · 2.1 KB
/
content.js
File metadata and controls
83 lines (72 loc) · 2.1 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
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
function getArticleDetails() {
// debugger;
data = {"body" : document.getElementsByClassName('Article')[0].innerText}
// debugger;
return data;
}
function fetchResource(input, init) {
return new Promise((resolve, reject) => {
chrome.runtime.sendMessage({input, init}, messageResponse => {
const [response, error] = messageResponse;
if (response === null) {
reject(error);
} else {
const body = response.body ? new Blob([response.body]) : undefined;
resolve(new Response(body, {
status: response.status,
statusText: response.statusText,
}));
}
});
});
}
function addRelevantArticles(details){
// debugger;
element1 = document.getElementsByClassName('Article')
// debugger;
len = details.articles.length
art = details.articles
// debugger;
element = element1[0]
element.innerText = element.innerText += '\n'
element.innerText = element.innerText += 'Related Articles\n '
var list_of_links = ""
for(var i = 0; i < len; i++){
link = "<p><a href=\""+art[i].url+"\">"+(art[i].title.replace(/'/g,''))+"</a></p>"
list_of_links = list_of_links += link
list_of_links = list_of_links += '\n'
}
// debugger;
const winHtml = `<!DOCTYPE html>
<html>
<head>
<title>Relevant Articles</title>
</head>
<body>
<h1>Relevant Articles</h1>
${list_of_links}
</body>
</html>`;
const winUrl = URL.createObjectURL(
new Blob([winHtml], { type: "text/html" })
);
const win = window.open(
winUrl,
"win",
`width=800,height=400,screenX=200,screenY=200`
);
}
// debugger;
data2 = getArticleDetails()
// debugger;
fetchResource('http://127.0.0.1:5000/get_top_results', {
method: 'post',
body: JSON.stringify(data),
headers: {
'Content-Type': 'application/json'
}
})
.then((res) => res.json())
.then(function(res){
addRelevantArticles(res)
})