-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontent_script.js
More file actions
44 lines (36 loc) · 1.13 KB
/
content_script.js
File metadata and controls
44 lines (36 loc) · 1.13 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
console.log("Extracting the data");
function extractData() {
let table$ = document.querySelector(".most-numbers");
let rows$ = table$.querySelectorAll("tr");
let result = [];
let companyName$ = document.querySelector(".classic tbody tr td:nth-child(2)");
let companyName = companyName$.textContent;
for (let row$ of rows$) {
let columns$ = row$.querySelectorAll("td");
if (columns$.length === 3) {
result.push({
name: normalizeName(columns$[0].textContent),
amount: normalizeAmount(columns$[1].textContent),
precent: normalizePrecent(columns$[2].textContent),
});
}
}
return {
name: companyName,
rows: result,
};
}
function normalizeName(name) {
return name.toLowerCase().trim();
}
function normalizeAmount(amount) {
return parseInt(amount.replace(/\s/ig, "").trim(), 10);
}
function normalizePrecent(precent) {
return parseFloat(precent.replace(" %", "").replace(",", "."));
}
chrome.runtime.sendMessage({
type: "extract",
created: Date.now(),
data: extractData(),
});