Last active
January 14, 2023 03:56
-
-
Save vaporwavie/353971ae37bb58425ed369e23cf48aec to your computer and use it in GitHub Desktop.
csgostats.gg scraping that lists your matches based on specific filters.
This file contains 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
function getRowText(t,e){return t.querySelector(e).innerText.trim()}let csgo=document.querySelectorAll("#match-list-outer > table > tbody > tr"),csgoMatches=[...csgo].map(t=>({date:getRowText(t,"td:nth-of-type(1)"),map:getRowText(t,"td:nth-of-type(3)"),score:getRowText(t,"td:nth-of-type(4)"),kills:+getRowText(t,"td.col-stats:nth-of-type(7)"),deaths:+getRowText(t,"td.col-stats:nth-of-type(8)"),diff:+getRowText(t,"td.col-stats:nth-of-type(10)"),rating:+getRowText(t,"td:nth-last-child(2)")}));function filterMatches(t="date"){const e=Object.keys(csgoMatches[0]);if(!e.some(e=>e===t))throw Error(`Invalid filter. Try using: ${e.join(", ")}. You could also just run it without a filter.`);return csgoMatches.sort((e,o)=>o[t]-e[t])} |
Unminified version:
function getRowText(element, selector) {
return element.querySelector(selector).innerText.trim();
}
let csgo = document.querySelectorAll("#match-list-outer > table > tbody > tr");
let csgoMatches = [...csgo].map((row) => ({
date: getRowText(row, "td:nth-of-type(1)"),
map: getRowText(row, "td:nth-of-type(3)"),
score: getRowText(row, "td:nth-of-type(4)"),
kills: +getRowText(row, "td.col-stats:nth-of-type(7)"),
deaths: +getRowText(row, "td.col-stats:nth-of-type(8)"),
diff: +getRowText(row, "td.col-stats:nth-of-type(10)"),
rating: +getRowText(row, "td:nth-last-child(2)"),
}));
function filterMatches(filterBy = "date") {
const acceptedFilters = Object.keys(csgoMatches[0]);
if (!acceptedFilters.some((filter) => filter === filterBy))
throw Error(
`Invalid filter. Try using: ${acceptedFilters.join(
", "
)}. You could also just run it without a filter.`
);
return csgoMatches.sort((a, b) => b[filterBy] - a[filterBy]);
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Installing
Enter
Usage
When injected, just run the function by typing
filterMatches()
. See the docs below for further info on the allowed filters.Docs
fn
filterMatches(filterBy?: string)
Accepts the following filter keys:
date
,map
,score
,kills
,deaths
,diff
andrating
and will default todate
when no argument is passed.