-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexportpwp.js
58 lines (49 loc) · 3.44 KB
/
exportpwp.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
const checkEverythingIsLoaded = setInterval(isLoaded, 5000);
const totalEventsToLoad = document.querySelectorAll('a.Expand').length;
document.querySelectorAll('a.Expand').forEach(a=>{
a.focus();
a.click();
});
function saveCSV(){
let content = '"date","description","store","location","participation points","points","pro points","multiplier","total event players","format","place","round number","result","opponent"\r\n';
document.querySelectorAll('.HistoryPanelRow').forEach(row=>{
const date = row.querySelector('.Date').innerText.trim() || "";
const description = row.querySelector('.Description').innerText.trim().replace(/(")/gm,'""') || "";
const location = row.querySelector('.Location').innerText.replace(/(")/gm,'""').trim() || "";
const lifetimepoints = row.querySelector('.LifetimePoints').innerText.trim() || "";
const propoints = row.querySelector('.ProPoints').innerText.trim() || "";
const participationpoints = row.querySelector('.EventParticipationPoints') ? row.querySelector('.EventParticipationPoints').innerText.replace(row.querySelector('.EventParticipationPoints b').innerText,'').trim() : "";
const multiplier = row.querySelector('.EventMultiplier') ? row.querySelector('.EventMultiplier').innerText.replace(row.querySelector('.EventMultiplier b').innerText,'').trim() : "";
const totalPlayers = row.querySelector('.EventPlayers') ? row.querySelector('.EventPlayers').innerText.replace(row.querySelector('.EventPlayers b').innerText,"").trim() : "";
const eventFormat = row.querySelector('.EventFormat') ? row.querySelector('.EventFormat').innerText.replace(row.querySelector('.EventFormat b').innerText,"").trim() : "";
const eventLocation = row.querySelector('.EventLocation') ? row.querySelector('.EventLocation').innerText.replace(row.querySelector('.EventLocation b').innerText,'').replace(/(")/gm,'""').trim() : "";
const place = row.querySelector('.EventPlace') ? row.querySelector('.EventPlace').innerText.replace(row.querySelector('.EventPlace b').innerText,'').trim() : "";
row.querySelectorAll('.MatchHistoryTable .MatchHistoryRow').forEach(match=>{
const roundNumber = match.querySelector('.MatchPlace') ? match.querySelector('.MatchPlace').innerText.trim() : "";
const result = match.querySelector('.MatchResult') ? match.querySelector('.MatchResult').innerText.trim() : "";
let opp = '';
if(match.querySelector('.MatchOpponentTeam')){
match.querySelectorAll('.MatchOpponentTeam div').forEach(teamopp=>{
opp += teamopp.innerText.trim().replace(/(")/gm,'""') + ', ';
});
opp = opp.slice(0, -2);
}
else {
opp = match.querySelector('.MatchOpponent') ? match.querySelector('.MatchOpponent').innerText.trim().replace(/(")/gm,'""') : "";
}
content += `"${date}","${description}","${location}","${eventLocation}","${participationpoints}","${lifetimepoints}","${propoints}","${multiplier}","${totalPlayers}","${eventFormat}","${place}","${roundNumber}","${result}","${opp}"\r\n`;
});
});
let link = document.createElement('a')
link.id = 'download-csv'
link.setAttribute('href', 'data:text/plain;charset=utf-8,' + encodeURIComponent(content));
link.setAttribute('download', 'pwp.export.csv');
document.body.appendChild(link)
document.querySelector('#download-csv').click();
}
function isLoaded(){
if(document.querySelectorAll('a.Expand').length == 0 && document.querySelectorAll('.EventSummary').length == totalEventsToLoad){
clearInterval(checkEverythingIsLoaded);
saveCSV();
}
}