-
Notifications
You must be signed in to change notification settings - Fork 0
/
tableToCsv
43 lines (42 loc) · 1.26 KB
/
tableToCsv
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
String.prototype.replaceAll = function (find, replace) {
var str = this;
return str.replace(new RegExp(find, 'g'), replace);
};
function fonk() {
var table = document.querySelector("#root > div > div.css-m1gtqz-body > main > div > div:nth-child(4) > div.css-1j8ngqv-tableRoot > div.css-1y0eoyp-tableWrapper > div > table");
var header=[];
var body=[];
var first=true;
var i=1;
for (let row of table.rows) {
let r=[]
for (let cell of row.cells) {
let val = cell.innerText;
if(val.trim()!=""){
r.push(val)
if(first){
header.push("Col"+i);
i++;
}
}
}
body.push(r)
first=false;
}
download( [header].concat(body) );
}
function download(array){
var result=""
for(x of array)
{
result+=x.map(x=> x.trim().replaceAll(",","").replaceAll("\n"," ")).join(",")+"\n";
}
var uri = 'data:text/csv;charset=utf-8,' + result;
var downloadLink = document.createElement("a");
downloadLink.href = uri;
downloadLink.download = "a.csv";
document.body.appendChild(downloadLink);
downloadLink.click();
document.body.removeChild(downloadLink);
}
fonk();