Skip to content

Instantly share code, notes, and snippets.

@Element00
Last active August 18, 2020 07:28
Show Gist options
  • Save Element00/6b1321427afc93e2fe3f4d3727aeeec6 to your computer and use it in GitHub Desktop.
Save Element00/6b1321427afc93e2fe3f4d3727aeeec6 to your computer and use it in GitHub Desktop.
// ==UserScript==
// @name Generals.io Statistics Page
// @namespace http://tampermonkey.net/
// @version 0.1
// @description try to take over the world!
// @author President Trump
// @match http://generals.io/profiles/*
// @match http://*.generals.io/profiles/*
// @grant none
// ==/UserScript==
var username = document.getElementsByClassName("profile-header")[0].firstElementChild.innerHTML;
var totalGames, total1v1wins, totalFFAwins, total2v2wins, totalCustomwins, total1v1, totalFFA, total2v2, totalCustom, searchGames, searchGamesWins, time;
totalGames = total1v1wins = totalFFAwins = total2v2wins = totalCustomwins = total1v1 = totalFFA = total2v2 = totalCustom = searchGames = searchGamesWins = time = 0;
var total1v1avg, totalFFAavg, totalCustomavg, total2v2avg, searchGamesavg;
total1v1avg = totalFFAavg = totalCustomavg = total2v2avg = searchGamesavg = 0;
var inGame = function(){};
var myObj, totalGames;
total1v1avg = totalFFAavg = totalCustomavg = total2v2avg = 0;
console.log(username);
function round(value, decimals) {
return Number(Math.round(value+'e'+decimals)+'e-'+decimals);
}
var xmlhttp = new XMLHttpRequest();
xmlhttp.onreadystatechange = function() {
if (this.readyState == 4 && this.status == 200) {
myObj = JSON.parse(this.responseText);
totalGames = Object.keys(myObj).length;
inGame = function(place, gameLength, object) {
var notInGame = false;
for (var j = 0; j < gameLength; j++){
if(object[place].ranking[j].name == username){
notInGame = true;
}
return notInGame;
}
};
check:
for(var i = 0; i < totalGames - 1;i++){
var gameSize = Object.keys(myObj[i].ranking).length;
var place1 = myObj[i].ranking[0].name;
var place2 = myObj[i].ranking[1].name;
var gameTime = myObj[i].turns;
if(((gameSize == 2 || gameSize <= 8) && (place1 == username || place2 == username)) || myObj[i].type == "2v2")
time += gameTime;
if(gameSize == 3 && myObj[i].ranking[2].name == username)
time += gameTime*0.9;
if(gameSize == 4 && myObj[i].ranking[3].name == username && myObj[i].type != "2v2")
time += gameTime*0.8;
if(gameSize == 5 && myObj[i].ranking[4].name == username)
time += gameTime*0.6;
if(gameSize == 6 && myObj[i].ranking[5].name == username)
time += gameTime*0.5;
if(gameSize == 7 && myObj[i].ranking[6].name == username)
time += gameTime*0.42;
if(gameSize == 8 && myObj[i].ranking[7].name == username)
time += gameTime*0.25;
if(gameSize == 2 && (myObj[i].type == "classic" || myObj[i].type == "1v1")){
if(place1 == username){
total1v1wins++;
}else if(!(place2 == username || place1 == username)){
total1v1--;
}
total1v1++;
continue;
}
if((gameSize > 2 && gameSize <= 8) && myObj[i].type == "classic"){
if(place1 == username){
totalFFAwins++;
}else if(inGame(i, gameSize, myObj)) {
totalFFA--;
ete++;
}
/* else if(place2 != username && place3 != username && place4 != username && place5 != username && place6 != username && place7 != username && place8 != username){
totalFFA--;
}*/
totalFFA++;
continue;
}
if(gameSize == 4 && myObj[i].type == "2v2"){
if(place1 == username || myObj[i].ranking[1].name == username){
total2v2wins++;
}
total2v2++;
continue;
}
if((gameSize >= 2 && gameSize <= 8) && myObj[i].type == "custom"){
if(gameSize == 2){
if(place1 == username){
totalCustomwins++;
} else if(!(place2 == username || place1 == username)){
totalCustom--;
}
}
if(gameSize > 2 && gameSize <= 8){
if(place1 == username){
totalCustomwins++;
}
}
totalCustom++;
}
}
var str1 = "Total Games: "+totalGames+"\nTime in game: "+round(time/2/60/60, 3)+" hours";
var str2 = "Total 1v1 Games: "+total1v1+"\nTotal 1v1 wins: "+total1v1wins+"\n1v1 Average: "+(total1v1wins/(total1v1==0? 1 : total1v1)*100).toFixed(2)+"%";
var str3 = "Total FFA Games: "+totalFFA+"\nTotal FFA wins: "+totalFFAwins+"\nFFA Average: "+(totalFFAwins/(totalFFA==0? 1 : totalFFA)*100).toFixed(2)+"%";
var str4 = "Total 2v2 Games: "+total2v2+"\nTotal 2v2 wins: "+total2v2wins+"\n2v2 Average: "+(total2v2wins/(total2v2==0? 1 : total2v2)*100).toFixed(2)+"%";
var str5 = "Total Custom Games: "+totalCustom+"\nTotal Custom wins: "+totalCustomwins+"\nCustom Average: "+(totalCustomwins/(totalCustom==0? 1 : totalCustom)*100).toFixed(2)+"%";
var statdiv = document.createElement("span");
var statdivText = document.createTextNode("");
var line1 = document.createTextNode(str1);
var row1 = document.createElement("tr");
row1.appendChild(line1);
var line2 = document.createTextNode(str2);
var row2 = document.createElement("tr");
row2.appendChild(line2);
var line3 = document.createTextNode(str3);
var row3 = document.createElement("tr");
row3.appendChild(line3);
var line4 = document.createTextNode(str4);
var row4 = document.createElement("tr");
row4.appendChild(line4);
var line5 = document.createTextNode(str5);
var row5 = document.createElement("tr");
row5.appendChild(line5);
statdiv.class = "table-responsive";
statdiv.appendChild(statdivText);
statdiv.appendChild(row1);
statdiv.appendChild(row2);
statdiv.appendChild(row3);
statdiv.appendChild(row4);
statdiv.appendChild(row5);
statdiv.id = "statdiv1";
var testbox = document.createElement("div");
var testboxText = document.createTextNode("");
testbox.appendChild(testboxText);
testbox.style.position = "fixed";
testbox.style.top = "1em";
testbox.style.right = "1em";
testbox.style.background = "#008080";
testbox.style.color = "white";
testbox.style.width = "26%";
testbox.style.whiteSpace = "pre-wrap";
testbox.style.borderStyle = "solid";
testbox.style.padding = "0.25% 0.5%";
testbox.style.textAlign = "left";
testbox.appendChild(statdiv);
var searchbox = document.createElement("input");
searchbox.setAttribute("type", "text");
searchbox.setAttribute("placeholder", "Search your 1v1 opponents...");
searchbox.id = "searchName";
searchbox.setAttribute("maxlength", "18");
searchbox.style.width = "90%";
var results = document.createElement("div");
results.id = "results1";
var searchResults = document.createTextNode("");
results.appendChild(searchResults);
testbox.appendChild(searchbox);
testbox.appendChild(results);
document.getElementsByTagName("center")[0].insertBefore(testbox, document.getElementsByClassName("rank-list")[0]);
}
};
xmlhttp.open("GET", "http://"+window.location.hostname+"/api/replaysForUsername?u="+username+"&offset=0&count=-1", true);
xmlhttp.send();
var x = setInterval(function(){
var results4 = document.getElementById("results1");
var searchUser = document.getElementById("searchName").value;
searchGamesWins = searchGames = 0;
loop:
for(var t = 0; t < totalGames; t++){
var gameSize = Object.keys(myObj[t].ranking).length;
var place1 = myObj[t].ranking[0].name;
var place2 = myObj[t].ranking[1].name;
if(gameSize == 2){
if((place1 == username || place2 == username) && (place1 == searchUser || place2 == searchUser)){
if(place1 == username){
searchGamesWins++;
}
searchGames++;
}
}
results4.innerHTML = "1v1 wins vs "+searchUser+" : "+searchGamesWins+" | Total Games: "+searchGames+" | Average: "+(searchGamesWins/(searchGames==0? 1 : searchGames)*100).toFixed(2)+"%";
}}, 750);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment