SHARE
TWEET

Artifact win-rate scraper

ltw_pastebin Dec 26th, 2018 (edited) 6,079 in 190 days
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // 1. In chrome or firefox, go to https://steamcommunity.com/my/gcpd/583950?category=Games&tab=MatchPlayers
  2. //
  3. // 2. If using chrome, find the top right menu (... button) and go: top right menu -> More tools -> Developer tools
  4. //    If using firefox, find the top right menu (pancake stack button) and go: top right menu -> Web Developer -> Web Console
  5. //
  6. // 3. Open the console and paste in this code then press enter
  7. //
  8. // 4. Paste your results to http://www.artifactcube.com/stats/
  9.  
  10. try {
  11.     if (!window.location.toString().endsWith("gcpd/583950?category=Games&tab=MatchPlayers"))
  12.     {
  13.         alert("You are on the incorrect page. Please run the script again after being redirected.");
  14.         window.location = "https://steamcommunity.com/my/gcpd/583950?category=Games&tab=MatchPlayers";
  15.     }
  16.  
  17.     var loadingDiv = null
  18.     if (document.getElementById("loadingDiv") == undefined)
  19.     {
  20.         loadingDiv = document.createElement("div");
  21.         loadingDiv.id = "loadingDiv"
  22.         document.body.append(loadingDiv);
  23.  
  24.         var loadingImg = document.createElement("img");
  25.         loadingImg.src="https://steamcommunity-a.akamaihd.net/public/images/login/throbber.gif";
  26.  
  27.         var loadingText = document.createElement("div");
  28.         loadingText.textContent = "loading matches please wait...";
  29.         loadingText.style = "margin-right: 10px;";
  30.  
  31.         loadingDiv.append(loadingText);
  32.         loadingDiv.append(loadingImg);
  33.     }
  34.     else {
  35.         loadingDiv = document.getElementById("loadingDiv");
  36.     }
  37.     loadingDiv.style="background:white ;border: 1px solid Black; position: fixed; top: 50%; left: 40%; padding: 20px; z-index: 100; display:flex; flex-direction: row; align-items: center;";
  38.  
  39.     if (document.getElementById("resultsDiv") != undefined)
  40.     {
  41.         document.getElementById("resultsDiv").style = "display:none;"
  42.     }
  43.  
  44.     mainContents = document.getElementById("mainContents");
  45.     mainContents.style = "display: none";
  46.  
  47.     matches = [];
  48.     var matchCounter = 0;
  49.  
  50.     var failures = 0;
  51.  
  52.     if (originalToken != undefined)
  53.     {
  54.         g_sGcContinueToken = originalToken;
  55.     }
  56.     var originalToken = g_sGcContinueToken;
  57.  
  58.     if (document.getElementById("personaldata_elements_container") == undefined)
  59.     {
  60.         throw "It appears you have no data.";
  61.     }
  62.     var existingTableRow = document.getElementById("personaldata_elements_container").getElementsByTagName('table')[0].getElementsByTagName('tbody')[0].getElementsByTagName('tr')[1];
  63.     var accountLink = existingTableRow.cells[1].getElementsByTagName('div')[0].getElementsByTagName('a')[0].href;
  64.     RecordData(existingTableRow);
  65.  
  66.     function RecordData(tableRow)
  67.     {
  68.  
  69.         var matchID = tableRow.cells[0].textContent;
  70.         var accountLink = tableRow.cells[1].getElementsByTagName('div')[0].getElementsByTagName('a')[0].href;
  71.         var accountID = accountLink.split("/")[accountLink.split("/").length - 1];
  72.         var matchTime = tableRow.cells[3].textContent;
  73.         var serverVersion = tableRow.cells[4].textContent;
  74.         var outcome = tableRow.cells[5].textContent;
  75.         var turns = tableRow.cells[6].textContent;
  76.         var gameTime = tableRow.cells[7].textContent;
  77.         var team = tableRow.cells[9].textContent;
  78.         var tower1 = tableRow.cells[11].textContent;
  79.         var tower2 = tableRow.cells[12].textContent;
  80.         var tower3 = tableRow.cells[13].textContent;
  81.         var ancient = tableRow.cells[14].textContent;
  82.         var timeLeft = tableRow.cells[15].textContent;
  83.         var hero1 = tableRow.cells[16].textContent;
  84.         var hero2 = tableRow.cells[17].textContent;
  85.         var hero3 = tableRow.cells[18].textContent;
  86.         var hero4 = tableRow.cells[19].textContent;
  87.         var hero5 = tableRow.cells[20].textContent;
  88.         var gauntletID = tableRow.cells[21].textContent;
  89.  
  90.         match = {};
  91.         match["matchID"] = matchID;
  92.         match["accountID"] = accountID;
  93.         match["matchTime"] = matchTime;
  94.         match["serverVersion"] = serverVersion;
  95.         match["outcome"] = outcome;
  96.         match["turns"] = turns;
  97.         match["gameTime"] = gameTime;
  98.         match["team"] = team;
  99.         match["tower1"] = tower1;
  100.         match["tower2"] = tower2;
  101.         match["tower3"] = tower3;
  102.         match["ancient"] = ancient;
  103.         match["timeLeft"] = timeLeft;
  104.         match["hero1"] = hero1;
  105.         match["hero2"] = hero2;
  106.         match["hero3"] = hero3;
  107.         match["hero4"] = hero4;
  108.         match["hero5"] = hero5;
  109.         match["gauntletID"] = gauntletID;
  110.         match["isWin"] = outcome == team;
  111.         match["isDraw"] = outcome == 8;
  112.  
  113.         if (!(hero1 == "0") && !(hero2 == "0") && !(hero3 == "0") && !(hero4 == "0") && !(hero5 == "0"))
  114.         {
  115.             console.log("------------ match ----------");
  116.             for (var key in match){
  117.                 console.log(key + ": " + match[key]);
  118.             }
  119.  
  120.             matches.push(match);
  121.             matchCounter ++;
  122.         }
  123.     }
  124.  
  125.     function GetNextData()
  126.     {
  127.         if (g_sGcContinueToken == null ||  g_sGcContinueToken == undefined)
  128.         {
  129.             ShowAlertDialog( 'Error', 'Failed because the history token is missing. Please inform the script creator.', 'OK' );
  130.         }
  131.         if (g_sessionID == null || g_sessionID == undefined)
  132.         {
  133.             ShowAlertDialog( 'Error', 'Failed because the session token is missing. Please inform the script creator.', 'OK' );
  134.         }
  135.         var request_data = {
  136.             ajax: 1,
  137.             tab: 'MatchPlayers',
  138.             continue_token: g_sGcContinueToken,
  139.             sessionid: g_sessionID
  140.         };
  141.         $J.ajax({
  142.             type: "GET",
  143.             url: accountLink + "/gcpd/583950",
  144.             data: request_data
  145.         }).done( function( data ) {
  146.             if ( data.success )
  147.             {
  148.                 if ( data.html )
  149.                 {
  150.                     var resultDataDOM = new DOMParser().parseFromString( data.html , 'text/html').body.firstChild;
  151.  
  152.                     var tableRow = resultDataDOM.rows[resultDataDOM.rows.length-1];
  153.  
  154.                     RecordData(tableRow);
  155.                 }
  156.  
  157.                 failures = 0;
  158.  
  159.                 if ( data.continue_token )
  160.                 {
  161.                     g_sGcContinueToken = data.continue_token;
  162.                     loadingText.textContent = "loading matches please wait... (" + matchCounter + " loaded)";
  163.                     setTimeout(GetNextData, 100);
  164.                 }
  165.                 else {
  166.                     g_sGcContinueToken = null;
  167.                     setTimeout(processData, 100);
  168.                 }
  169.             }
  170.             else
  171.             {
  172.                 failures++;
  173.                 if (failures > 5)
  174.                 {
  175.                     ShowAlertDialog( 'Error', 'Artifact servers have returned invalid data. Sorry. Please try again.', 'OK' );
  176.                 }
  177.                 else
  178.                 {
  179.                     setTimeout(GetNextData, 1000);
  180.                 }
  181.             }
  182.         }).fail( function( jqXHR ) {
  183.             if ( jqXHR.status == 429 )
  184.             {
  185.                 failures++;
  186.                 if (failures > 5)
  187.                 {
  188.                     ShowAlertDialog( 'Error', 'Artifact servers have rate-limited you', 'OK' );
  189.                 }
  190.                 else
  191.                 {
  192.                     setTimeout(GetNextData, 1000);
  193.                 }
  194.             }
  195.             else
  196.             {
  197.                 failures++;
  198.                 if (failures > 5)
  199.                 {
  200.                     ShowAlertDialog( 'Error', 'Artifact serves have returned an error. Sorry. Please try again.', 'OK' );
  201.                 }
  202.                 else
  203.                 {
  204.                     setTimeout(GetNextData, 1000);
  205.                 }
  206.             }
  207.         });
  208.     }
  209.  
  210.     GetNextData();
  211.     function processData() {
  212.         loadingDiv.style = "display: none";
  213.        
  214.         var resultsDiv = null;
  215.         var dataDiv = null;
  216.         if (document.getElementById("resultsDiv") == undefined)
  217.         {
  218.             resultsDiv = document.createElement("div");
  219.             resultsDiv.id = "resultsDiv"
  220.             document.body.append(resultsDiv);
  221.  
  222.             var dataDivTitle = document.createElement("h2");
  223.             resultsDiv.append(dataDivTitle);
  224.             dataDivTitle.innerHTML = "To see your results, copy the below text and paste it at <a style=\\\"color:blue\\\" href=\\\"https://www.artifactcube.com/stats/\\\" target=\\\"_Blank\\\">artifactcube.com</a>.";
  225.  
  226.             dataDiv = document.createElement("textarea");
  227.  
  228.             dataDiv.spellcheck=false;
  229.             dataDiv.readonly=true;
  230.             dataDiv.id = "dataDiv"
  231.             dataDiv.style="width: 1000px; height: 200px"
  232.             resultsDiv.append(dataDiv);
  233.         }
  234.         else {
  235.             resultsDiv = document.getElementById("resultsDiv")
  236.             dataDiv = document.getElementById("dataDiv")
  237.         }
  238.         resultsDiv.style="background:white ;border: 1px solid Black; position: fixed; top: 50%; left: 0%; padding: 20px; z-index: 100; display:flex; flex-direction: column; align-items: center;";
  239.  
  240.         dataDiv.textContent = JSON.stringify(matches);
  241.     }
  242. }
  243. catch (e)
  244. {
  245.     ShowAlertDialog( 'Error', 'Script encountered an error: ' + e.toString(), 'OK' );
  246. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top