-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcontent_script.js
38 lines (34 loc) · 1.25 KB
/
content_script.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
const text = document.querySelectorAll('h1, h2, h3, h4, h5, p, li, td, caption, span, a')
function textCheck(myQuery)
{
count = 0;
for(let i = 0; i < text.length; i++)
{
//causes severe usability issues if the html replace happens too often, but i dont think we need to worry about that too much for now. Just don't use a high frequency term like 'a'
if(text[i].innerHTML.includes(myQuery)){
//console.log(text[i].innerHTML)
//text[i].innerHTML = text[i].innerHTML.replaceAll(new RegExp(myQuery, "g"), "MEV1")
count++;
}
}
return count;
}
chrome.runtime.onMessage.addListener(
function(message, sender, sendResponse) {
switch(message.type) {
case "getCount":
worldData = [];
message.myQuery.forEach(function(countryData) {
var result = textCheck(countryData.CountryName);
if(result > 0)
{
worldData.push(countryData.CountryName);
}
});
sendResponse(JSON.stringify(worldData));
break;
default:
console.error("Unrecognised message: ", message);
}
}
);