Created
December 29, 2018 13:00
-
-
Save ducnh1022/cb3b651113944f6b06d183ad8b821b46 to your computer and use it in GitHub Desktop.
artifact script
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
var loadingDiv = document.createElement("div"); | |
loadingDiv.style="background:white ;border: 1px solid Black; position: fixed; top: 50%; left: 50%; padding: 20px; z-index: 100; display:flex; flex-direction: row; align-items: center;"; | |
document.body.append(loadingDiv); | |
var loadingImg = document.createElement("img"); | |
loadingImg.src="https://steamcommunity-a.akamaihd.net/…/…/login/throbber.gif"; | |
var loadingText = document.createElement("div"); | |
loadingText.textContent = "loading matches please wait..."; | |
loadingText.style = "margin-right: 10px;"; | |
loadingDiv.append(loadingText); | |
loadingDiv.append(loadingImg); | |
hero_data = {'Ogre Magi': {'color': 'blue', 'image': 'https://steamcdn-a.akamaihd.net/…/10043.4b52a60db821028ba02…'}, 'Keefe the Bold': {'color': 'red', 'image': 'https://steamcdn-a.akamaihd.net/…/4003.2cc81eb5cf6375fdfad1…'}, 'Skywrath Mage': {'color': 'blue', 'image': 'https://steamcdn-a.akamaihd.net/…/10062.320871aec38db2b973d…'}, 'Timbersaw': {'color': 'red', 'image': 'https://steamcdn-a.akamaihd.net/…/10022.065c0b1ce65b1f201bc…'}, 'Magnus': {'color': 'green', 'image': 'https://steamcdn-a.akamaihd.net/…/10067.9130bf7958f290e69cf…'}, 'Omniknight': {'color': 'green', 'image': 'https://steamcdn-a.akamaihd.net/…/10044.5fe4f8195b2a005f6b4…'}, 'Viper': {'color': 'green', 'image': 'https://steamcdn-a.akamaihd.net/…/10028.50b8bc7588cab219f86…'}, 'Storm Spirit': {'color': 'black', 'image': 'https://steamcdn-a.akamaihd.net/…/10536.f29d6a820bf65991ea1…'}, 'Ursa': {'color': 'red', 'image': 'https://steamcdn-a.akamaihd.net/…/10070.0fb457ff9ef3010b7f2…'}, 'Prellex': {'color': 'blue', 'image': 'https://steamcdn-a.akamaihd.net/…/10053.46d6ca300f26d8e05aa…'}, 'Lycan': {'color': 'green', 'image': 'https://steamcdn-a.akamaihd.net/…/10014.d0b682f37b2b7b77707…'}, 'Sniper': {'color': 'black', 'image': 'https://steamcdn-a.akamaihd.net/…/10050.be0a865d3d49ca386d2…'}, 'Meepo': {'color': 'blue', 'image': 'https://steamcdn-a.akamaihd.net/…/10004.8e77e6463c971dab1fa…'}, 'Winter Wyvern': {'color': 'black', 'image': 'https://steamcdn-a.akamaihd.net/…/10010.ad0a64e7f9814fc0cb1…'}, 'Venomancer': {'color': 'blue', 'image': 'https://steamcdn-a.akamaihd.net/…/10001.c2456641c9dd1b758dd…'}, 'Crystal Maiden': {'color': 'blue', 'image': 'https://steamcdn-a.akamaihd.net/…/10064.e76bb6f2b597ae16bc8…'}, 'Zeus': {'color': 'blue', 'image': 'https://steamcdn-a.akamaihd.net/…/10065.de19a6f1e68cfcab2f3…'}, 'Beastmaster': {'color': 'red', 'image': 'https://steamcdn-a.akamaihd.net/…/10029.9deae28f2a6715b2456…'}, 'Lion': {'color': 'black', 'image': 'https://steamcdn-a.akamaihd.net/…/10060.1b8ab00d3d43fa0aec1…'}, 'Bloodseeker': {'color': 'black', 'image': 'https://steamcdn-a.akamaihd.net/…/10018.99a88322fecd54fc5fe…'}, 'Sven': {'color': 'red', 'image': 'https://steamcdn-a.akamaihd.net/…/10054.f7ec19918c68fa805f4…'}, 'Tinker': {'color': 'black', 'image': 'https://steamcdn-a.akamaihd.net/…/10025.33033b1e8b19d9a9343…'}, 'Drow Ranger': {'color': 'green', 'image': 'https://steamcdn-a.akamaihd.net/…/10032.ac3532fc6482ff60374…'}, "J'Muy the Wise": {'color': 'blue', 'image': 'https://steamcdn-a.akamaihd.net/…/4008.35f4da08e371db6ecc07…'}, 'Centaur Warrunner': {'color': 'red', 'image': 'https://steamcdn-a.akamaihd.net/…/10021.f655334174b3964b586…'}, 'Treant Protector': {'color': 'green', 'image': 'https://steamcdn-a.akamaihd.net/…/10056.4ea3388b448c9ee13bb…'}, 'Farvhan the Dreamer': {'color': 'green', 'image': 'https://steamcdn-a.akamaihd.net/…/4000.049cff338ab7274d0dcd…'}, 'Dark Seer': {'color': 'green', 'image': 'https://steamcdn-a.akamaihd.net/…/10068.e8e173ac8dd4f1d582f…'}, 'Kanna': {'color': 'blue', 'image': 'https://steamcdn-a.akamaihd.net/…/10031.967b53755c3a477cc89…'}, 'Outworld Devourer': {'color': 'blue', 'image': 'https://steamcdn-a.akamaihd.net/…/10046.959caac2a5c3a0e8efe…'}, 'Abaddon': {'color': 'green', 'image': 'https://steamcdn-a.akamaihd.net/…/10016.49550e3b17ccf2611eb…'}, 'Axe': {'color': 'red', 'image': 'https://steamcdn-a.akamaihd.net/…/10020.023febd622949d771d9…'}, 'Debbi the Cunning': {'color': 'black', 'image': 'https://steamcdn-a.akamaihd.net/…/4005.ceab77c296987994f9df…'}, 'Bristleback': {'color': 'red', 'image': 'https://steamcdn-a.akamaihd.net/…/10030.d6427ab9016cda608a6…'}, 'Lich': {'color': 'black', 'image': 'https://steamcdn-a.akamaihd.net/…/10038.26778b9a203a57b0d3f…'}, 'Earthshaker': {'color': 'blue', 'image': 'https://steamcdn-a.akamaihd.net/…/10033.7c8e9fa3eccd923d843…'}, 'Pugna': {'color': 'red', 'image': 'https://steamcdn-a.akamaihd.net/…/10048.ca73a1b73aa37fc74a7…'}, 'Rix': {'color': 'green', 'image': 'https://steamcdn-a.akamaihd.net/…/10026.59c2df4317db54a08c4…'}, 'Legion Commander': {'color': 'red', 'image': 'https://steamcdn-a.akamaihd.net/…/10069.f0595417e162f98c02c…'}, 'Mazzie': {'color': 'red', 'image': 'https://steamcdn-a.akamaihd.net/…/10052.16b67615c0229d72fd9…'}, 'Bounty Hunter': {'color': 'black', 'image': 'https://steamcdn-a.akamaihd.net/…/10023.503fcb60e0cdc30aa1d…'}, 'Luna': {'color': 'blue', 'image': 'https://steamcdn-a.akamaihd.net/…/10006.ee9329205440996f09b…'}, 'Tidehunter': {'color': 'red', 'image': 'https://steamcdn-a.akamaihd.net/…/10024.1ffefd6bce93c5753f5…'}, 'Sorla Khan': {'color': 'black', 'image': 'https://steamcdn-a.akamaihd.net/…/10058.635583094b11fcc0f86…'}, 'Phantom Assassin': {'color': 'black', 'image': 'https://steamcdn-a.akamaihd.net/…/10047.dd94f5bc1b22bef2e9b…'}, 'Chen': {'color': 'green', 'image': 'https://steamcdn-a.akamaihd.net/…/10017.c755182fd873b5df7f4…'}, 'Enchantress': {'color': 'green', 'image': 'https://steamcdn-a.akamaihd.net/…/10036.995dc56212e8e8bf404…'}, 'Necrophos': {'color': 'black', 'image': 'https://steamcdn-a.akamaihd.net/…/10059.66aae3f23e16000eb90…'}} | |
div_color = { | |
"black": "#999999", | |
"red": "#aa3333", | |
"green": "#33aa33", | |
"blue" : "#6666aa" | |
} | |
matches = {}; | |
var matchCounter = 0; | |
var failures = 0; | |
function GetNextData() | |
{ | |
if (g_sGcContinueToken == null || g_sGcContinueToken == undefined) | |
{ | |
ShowAlertDialog( 'Error', 'Failed because the history token is missing. Please inform the script creator.', 'OK' ); | |
} | |
if (g_sessionID == null || g_sessionID == undefined) | |
{ | |
ShowAlertDialog( 'Error', 'Failed because the session token is missing. Please inform the script creator.', 'OK' ); | |
} | |
var request_data = { | |
ajax: 1, | |
tab: 'MatchPlayers', | |
continue_token: g_sGcContinueToken, | |
sessionid: g_sessionID | |
}; | |
$J.ajax({ | |
type: "GET", | |
url: "https://steamcommunity.com/my/gcpd/583950", | |
data: request_data | |
}).done( function( data ) { | |
if ( data.success ) | |
{ | |
if ( data.html ) | |
{ | |
var resultDataDOM = new DOMParser().parseFromString( data.html , 'text/html').body.firstChild; | |
var tableRow = resultDataDOM.rows[resultDataDOM.rows.length-1]; | |
var matchID = tableRow.cells[0].textContent; | |
var matchTime = tableRow.cells[3].textContent; | |
var outcome = tableRow.cells[5].textContent; | |
var turns = tableRow.cells[6].textContent; | |
var team = tableRow.cells[9].textContent; | |
var tower1 = tableRow.cells[11].textContent; | |
var tower2 = tableRow.cells[12].textContent; | |
var tower3 = tableRow.cells[13].textContent; | |
var ancient = tableRow.cells[14].textContent; | |
var timeLeft = tableRow.cells[15].textContent; | |
var hero1 = tableRow.cells[16].textContent; | |
var hero2 = tableRow.cells[17].textContent; | |
var hero3 = tableRow.cells[18].textContent; | |
var hero4 = tableRow.cells[19].textContent; | |
var hero5 = tableRow.cells[20].textContent; | |
var gauntletID = tableRow.cells[21].textContent; | |
var deckCode = tableRow.cells[22].textContent; | |
match = {}; | |
match["matchID"] = matchID; | |
match["matchTime"] = matchTime; | |
match["outcome"] = outcome; | |
match["turns"] = turns; | |
match["team"] = team; | |
match["tower1"] = tower1; | |
match["tower2"] = tower2; | |
match["tower3"] = tower3; | |
match["ancient"] = ancient; | |
match["timeLeft"] = timeLeft; | |
match["hero1"] = hero1; | |
match["hero2"] = hero2; | |
match["hero3"] = hero3; | |
match["hero4"] = hero4; | |
match["hero5"] = hero5; | |
match["gauntletID"] = gauntletID; | |
match["isWin"] = outcome == team; | |
match["deck"] = deckCode; | |
if (!(hero1 == "0") && !(hero2 == "0") && !(hero3 == "0") && !(hero4 == "0") && !(hero5 == "0")) | |
{ | |
console.log("------------ match ----------"); | |
for (var key in match){ | |
console.log(key + ": " + match[key]); | |
} | |
if (matches[gauntletID] == undefined) | |
{ | |
matches[gauntletID] = [] | |
} | |
matches[gauntletID].push(match); | |
matchCounter ++; | |
} | |
} | |
failures = 0; | |
if ( data.continue_token ) | |
{ | |
g_sGcContinueToken = data.continue_token; | |
loadingText.textContent = "loading matches please wait... (" + matchCounter + " loaded)"; | |
setTimeout(GetNextData, 100); | |
} | |
else { | |
g_sGcContinueToken = null; | |
setTimeout(processData, 100); | |
} | |
} | |
else | |
{ | |
failures++; | |
if (failures > 5) | |
{ | |
ShowAlertDialog( 'Error', 'Artifact servers have returned invalid data. Sorry. Please try again.', 'OK' ); | |
} | |
else | |
{ | |
setTimeout(GetNextData, 1000); | |
} | |
} | |
}).fail( function( jqXHR ) { | |
if ( jqXHR.status == 429 ) | |
{ | |
failures++; | |
if (failures > 5) | |
{ | |
ShowAlertDialog( 'Error', 'Artifact servers have rate-limited you', 'OK' ); | |
} | |
else | |
{ | |
setTimeout(GetNextData, 1000); | |
} | |
} | |
else | |
{ | |
failures++; | |
if (failures > 5) | |
{ | |
ShowAlertDialog( 'Error', 'Artifact serves have returned an error. Sorry. Please try again.', 'OK' ); | |
} | |
else | |
{ | |
setTimeout(GetNextData, 1000); | |
} | |
} | |
}); | |
} | |
GetNextData(); | |
function processData() { | |
loadingDiv.style = "display: none"; | |
mainContents = document.getElementById("mainContents"); | |
var resultsDiv = document.createElement("div"); | |
mainContents.insertBefore(resultsDiv, mainContents.firstChild); | |
for (var gauntletID in matches) | |
{ | |
var gauntletDiv = document.createElement("div"); | |
resultsDiv.append(gauntletDiv); | |
gauntletDiv.style = "margin-top: 20px;" | |
if (gauntletID == 0) | |
{ | |
gauntletDiv.textContent = "-------------------------- Constructed --------------------------"; | |
} | |
else if (gauntletID == 8) | |
{ | |
gauntletDiv.textContent = "-------------------------- Prize Phantom Draft --------------------------"; | |
} | |
else if (gauntletID == 11) | |
{ | |
gauntletDiv.textContent = "-------------------------- Standard Phantom Draft --------------------------"; | |
} | |
else if (gauntletID == 5) | |
{ | |
gauntletDiv.textContent = "-------------------------- Call To Arms --------------------------"; | |
} | |
else if (gauntletID == 9) | |
{ | |
gauntletDiv.textContent = "-------------------------- Keeper Draft --------------------------"; | |
} | |
else { | |
gauntletDiv.textContent = "------------- gauntlet #" + gauntletID + " (unknown, let script creator know what mode you think this is) ------------------"; | |
} | |
gauntletMatches = matches[gauntletID]; | |
var winCount = 0; | |
var i = 0; | |
for (i = 0; i < gauntletMatches.length; i++) | |
{ | |
var match = gauntletMatches[i]; | |
if (match["isWin"] == true) | |
{ | |
winCount ++; | |
} | |
} | |
var gamesDiv = document.createElement("div"); | |
resultsDiv.append(gamesDiv); | |
gamesDiv.textContent = "Games Played: " + gauntletMatches.length; | |
var winsDiv = document.createElement("div"); | |
resultsDiv.append(winsDiv); | |
winsDiv.textContent = "Win rate: " + (winCount * 100/gauntletMatches.length).toFixed(3) + "%"; | |
var hero_stats = {} | |
for (i = 0; i < gauntletMatches.length; i++) | |
{ | |
var match = gauntletMatches[i]; | |
for (var j = 1; j <= 5; j++) | |
{ | |
hero = match["hero"+j]; | |
if (hero_stats[hero] == undefined) | |
{ | |
hero_stats[hero] = {}; | |
hero_stats[hero]["num_games"] = 0; | |
hero_stats[hero]["num_wins"] = 0; | |
} | |
hero_stats[hero]["num_games"]++; | |
if (match["isWin"] == true) | |
{ | |
hero_stats[hero]["num_wins"]++; | |
} | |
} | |
} | |
var heroGames = []; | |
var heroWinRates = []; | |
for (var hero in hero_stats) { | |
heroGames.push([hero, hero_stats[hero]["num_games"]]); | |
heroWinRates.push([hero, hero_stats[hero]["num_games"], hero_stats[hero]["num_wins"]/hero_stats[hero]["num_games"]]); | |
} | |
heroGames.sort(function(a, b) { | |
return b[1] - a[1]; | |
}); | |
heroWinRates.sort(function(a, b) { | |
return b[2] - a[2]; | |
}); | |
var heroGamesDiv = document.createElement("div"); | |
resultsDiv.append(heroGamesDiv); | |
heroGamesDiv.style = "margin-top: 10px;" | |
heroGamesDiv.textContent = " --- Top heroes played ---"; | |
for (i = 0; i < heroGames.length; i++) | |
{ | |
var heroGamesDiv = document.createElement("div"); | |
resultsDiv.append(heroGamesDiv); | |
heroGamesDiv.style = "color: " + div_color[hero_data[heroGames[i][0]].color]; | |
heroGamesDiv.textContent = heroGames[i][1] + " - " + heroGames[i][0]; | |
} | |
var heroGamesDiv = document.createElement("div"); | |
resultsDiv.append(heroGamesDiv); | |
heroGamesDiv.style = "margin-top: 10px;" | |
heroGamesDiv.textContent = " --- Top heroes win rate ---"; | |
for (i = 0; i < heroWinRates.length; i++) | |
{ | |
var heroGamesDiv = document.createElement("div"); | |
resultsDiv.append(heroGamesDiv); | |
heroGamesDiv.style = "color: " + div_color[hero_data[heroWinRates[i][0]].color]; | |
heroGamesDiv.textContent = (heroWinRates[i][2]*100).toFixed(1) + "% - " + heroWinRates[i][0] + " (games played: " + heroWinRates[i][1] + " )"; | |
} | |
var matchHistoryDiv = document.createElement("div"); | |
resultsDiv.append(matchHistoryDiv); | |
matchHistoryDiv.style = "margin-top: 10px;" | |
matchHistoryDiv.textContent = " --- Condensed match history ---"; | |
for (i = 0; i < gauntletMatches.length; i++) | |
{ | |
var match = gauntletMatches[i]; | |
var matchDiv = document.createElement("div"); | |
resultsDiv.append(matchDiv); | |
matchDiv.textContent = (match["isWin"] ? "win" : "loss") + " ---- " + match["hero1"] + ", " + match["hero2"] + ", " + match["hero3"] + ", " + match["hero4"] + ", " + match["hero5"] + ', playartifact.com/d/' + match["deck"]; | |
matchDiv.style = match["isWin"] ? "color:green" : "color:red"; | |
/*var heroImg = document.createElement("img"); | |
heroImg.src = hero_data[match.hero1].image; | |
resultsDiv.append(heroImg);*/ | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment