Skip to content

Instantly share code, notes, and snippets.

@Maistho
Created July 9, 2019 02:42
Show Gist options
  • Save Maistho/815209df7e227d83c247fa3dba38d268 to your computer and use it in GitHub Desktop.
Save Maistho/815209df7e227d83c247fa3dba38d268 to your computer and use it in GitHub Desktop.
CSGO stats bookmarklet
javascript:
(function () {
let CsgoMap;
(function (CsgoMap) {
CsgoMap["de_mirage"] = "Mirage";
CsgoMap["de_dust2"] = "Dust II";
CsgoMap["de_subzero"] = "Subzero";
CsgoMap["de_train"] = "Train";
CsgoMap["de_nuke"] = "Nuke";
CsgoMap["de_inferno"] = "Inferno";
CsgoMap["de_cache"] = "Cache";
CsgoMap["de_overpass"] = "Overpass";
})(CsgoMap || (CsgoMap = {}));
async function getAllMatches() {
if (window.location.hostname != 'steamcommunity.com') {
alert('Redirecting to steamcommunity.com, please run the bookmarklet again after the page has reloaded');
window.location.hostname = 'steamcommunity.com';
}
const userAvatar = document.querySelector('#global_actions>a.user_avatar');
if (!userAvatar) {
alert('You need to be logged in');
throw new Error('User not logged in');
}
const profileLink = userAvatar.href.replace(/\/$/, '');
const matches = [];
let continueToken;
do {
const params = new URLSearchParams({
ajax: '1',
tab: 'matchhistorycompetitive',
});
if (continueToken) {
params.append('continue_token', continueToken);
}
const response = await fetch(`${profileLink}/gcpd/730?${params.toString()}`, {
credentials: 'include',
}).then(res => res.json());
if (!response.success) {
throw new Error(JSON.stringify(response));
}
const parser = new DOMParser();
const dom = parser.parseFromString(response.html, 'text/html');
matches.push(...Array.from(dom.querySelectorAll('.generic_kv_table.csgo_scoreboard_root>tbody>tr'))
.map(tr => {
return Object.assign({ map: getMap(tr), time: getTime(tr), waitTime: getWaitTime(tr), matchDuration: getMatchDuration(tr), score: getScore(tr), demo: getDemo(tr) }, getTeams(tr, profileLink));
})
.filter(({ map }) => !!map));
continueToken = response.continue_token;
} while (continueToken);
return matches;
}
const getTeams = (tr, profileLink) => {
const teams = [[], []];
const players = Array.from(tr.querySelectorAll('.csgo_scoreboard_inner_right>tbody>tr'));
let currentTeam = -1;
for (const player of players) {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment