-
Notifications
You must be signed in to change notification settings - Fork 0
/
eventPage.js
100 lines (86 loc) · 2.93 KB
/
eventPage.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
chrome.browserAction.onClicked.addListener(function(tab) {
const executeScripts = (tabId, scripts) => {
return new Promise((resolve, reject) => {
try {
if (scripts.length && scripts.length > 0) {
const execute = (index = 0) => {
chrome.tabs.executeScript(tabId, scripts[index], () => {
const newIndex = index + 1;
if (scripts[newIndex]) {
execute(newIndex);
} else {
resolve();
}
});
}
execute();
} else {
throw new Error('scripts(array) undefined or empty');
}
} catch (err) {
reject(err);
}
});
};
executeScripts(
null,
[
{ file: "jquery-3.4.1.min.js" },
{ code: `
var a = document.body;
var b = a.getElementsByTagName("ARTICLE");
var c = b[0].getElementsByTagName("P");
var li = b[0].getElementsByTagName("LI");
var p_text = [];
var li_text = [];
for (var i = 0; i < c.length; i++) {
p_text[i] = c[i].textContent;
}
for (var i = 0; i < li.length; i++) {
p_text.push(li[i].textContent);
}
joined_text = p_text.join(' ');
var splitted_result_text = [];
$.ajax({
type: "POST",
url: "text-summarizer_url",
data : {
'text': joined_text,
'apikey': 'text-summarizer_apikey'
},
success: function(data){
result_text = data.result;
splitted_result_text = result_text.split("!").join(".").split("…").join(".").split(".");
/*
alert(splitted_result_text.length);
for(var j = 0; j<splitted_result_text.length; j++){
alert(splitted_result_text[j]);
}
*/
function doSearch(text, backgroundColor) {
if (window.find && window.getSelection) {
document.designMode = "on";
var sel = window.getSelection();
sel.collapse(document.body, 0);
while (window.find(text)) {
document.execCommand("HiliteColor", false, backgroundColor);
sel.collapseToEnd();
}
document.designMode = "off";
}
}
for(var j = 0; j<splitted_result_text.length; j++){
doSearch(splitted_result_text[j].trim(),"yellow");
}
},
error: function(msg){
alert(msg);
}
});
console.log("***SumediuM***");
`
}
]
).then(() => {
})
});