Last active
September 1, 2020 17:57
-
-
Save MikaelPorttila/7c968e498ae2ee3dd2ab45ca71622316 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const loadMoreBtn = document.getElementById('load_more_button'); | |
const loader = document.getElementById('inventory_history_loading'); | |
const exportData = () => { | |
const teamSize = 5; | |
const rows = [...document.querySelectorAll('#personaldata_elements_container > table > tbody > tr')]; | |
rows.shift(); // Remove header row. | |
const matches = rows.map((match) => { | |
const meta = [...match.querySelectorAll('.csgo_scoreboard_inner_left td')].map(node => node.innerText); | |
const scoreboardRight = match.querySelector('.csgo_scoreboard_inner_right'); | |
const statsRows = [...scoreboardRight.querySelectorAll('tr')]; | |
statsRows.shift(); // Remove header | |
statsRows.splice(teamSize, 1); // Remove score | |
const players = statsRows.map((player) => { | |
const playerDataColumns = player.querySelectorAll('td'); | |
const playerData = player.querySelector('.linkTitle'); | |
return { | |
id: playerData.getAttribute('href'), | |
ping: playerDataColumns[1].innerText, | |
kills: playerDataColumns[2].innerText, | |
assists: playerDataColumns[3].innerText, | |
deaths: playerDataColumns[4].innerText, | |
mvps: playerDataColumns[5].innerText, | |
hsp: playerDataColumns[6].innerText, | |
score: playerDataColumns[7].innerText | |
}; | |
}); | |
return { | |
map: meta[0], | |
date: meta[1], | |
wait: meta[2], | |
duration: meta[3], | |
score: scoreBoardRight.querySelector('.csgo_scoreboard_score').innerText, | |
team1: players.splice(0, teamSize), | |
team2: players | |
}; | |
}); | |
const csv = 'data:text/csv;charset=utf-8,' + matches.map((match) => { | |
// Export whatever... | |
return [...match.team1, ...match.team2].map(player => `${player.id}\n`).join(''); | |
/* return [ | |
match.date, | |
match.map, | |
match.score, | |
].join(',') + '\r\n' */ | |
}); | |
var data = encodeURI(csv); | |
var link = document.createElement("a"); | |
link.setAttribute("href", data); | |
link.setAttribute("download", "csgo-data.csv"); | |
document.body.appendChild(link); | |
link.click(); | |
} | |
const interval = setInterval(() => { | |
const loading = loader.style.display !== 'none'; | |
const loadMoreHidden = loadMoreBtn.style.display === 'none'; | |
if(!loading) { | |
loadMoreBtn.click(); | |
} | |
if(loadMoreHidden && !loading) { | |
clearInterval(interval); | |
exportData(); | |
alert('Done!') | |
} | |
}, 500); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment