// ==UserScript== // @name Agma.io stats // @namespace http://tampermonkey.net/ // @version 0.1.1 // @description See stats about your game in the death screen! // @author firebone & fishy // @match https://agma.io/ // @grant none // @downloadURL none // ==/UserScript== (function() { const ad = document.getElementById("zoomItem"); const statsDiv = document.createElement("div"); statsDiv.innerHTML =`

Gameplay Stats

Highest Mass Top Leaderboard
/ /
XP Gained Coins Gained
0 | 0% 0
Time Alive Powerups Used
0h 0min 0s 0
` ad.parentNode.replaceChild(statsDiv, ad); document.getElementById("advertDialog1").style.opacity = "0"; document.getElementById("advertDialog2").style.height = "250px" var plrAlive = false, level = 0, deathTime = 0, spawnedFirstTime = false; //insert values function stats(){ deathTime = Date.now(); plrAlive = false; document.getElementById("agmaAdHref").removeAttribute("href"); document.getElementById("agmaAdHref").parentElement.removeAttribute("onclick"); document.getElementById("advertContinue").parentElement.style.marginTop = "4px"; let gainedXp = Math.floor(calcXp() - xp) > 0 ? Math.floor(calcXp() - xp) : 0; let gainedPercent = Math.round(gainedXp / (level / 10)) / 100; document.getElementById('highestMass').innerText = topMass; document.getElementById('topLeader').innerText = topLeaderboard == 1e5 ? "/" : topLeaderboard; document.getElementById('xpGain').innerText = gainedXp + 'XP | ' + (gainedPercent ? gainedPercent : 0) + '%'; document.getElementById('coinGain').innerText = getCoins() - coins > 0 ? getCoins() - coins : "0"; document.getElementById('timeAlive').innerText = getTimeAlive(); document.getElementById('powsUsed').innerText = usedPowers; } //Track if player died var adv = document.getElementById('advert'); setInterval(check => { if(adv.style.display != 'none' && plrAlive){ stats(); } }, 300) //Track if player spawns let playFunction = window.setNick; window.setNick = function(nick, respawn){ playFunction(nick, respawn); if(!plrAlive){ plrAlive = true; deathTime = false; spawnedFirstTime = true; resetStats(); } else { respawn && setTimeout(resetStats, 1000); // otherwise stats wont show when dying by respawn }; } //Track stats var topMass, topLeaderboard, timeJoin, xp, coins, usedPowers, powerCount; setInterval(() => { let oldPowerCount = powerCount; powerCount = 0; let inv1 = document.getElementById('inventory1').children; let inv2 = document.getElementById('inventory2').children; for(let i = 0; i < inv1.length; i++){ let amnt = parseInt(inv1[i].innerText); if(isNaN(amnt)){ amnt = inv1[i].style.display == 'none' ? 0 : 1; } powerCount += amnt; } for(let i = 0; i < inv2.length; i++){ let amnt = parseInt(inv2[i].innerText); if(isNaN(amnt)){ amnt = inv2[i].style.display == 'none' ? 0 : 1; } powerCount += amnt; } if(oldPowerCount - powerCount > 0){ usedPowers += oldPowerCount - powerCount; } },1e3) function calcXp(){ level = parseInt(document.getElementById('level').innerText); var progress = parseFloat(document.getElementsByClassName('progress-bar')[0].style.width); return (level ** 2 * 0.5 - 0.5 * level) * 1000 + (level * 1000 * (progress / 100)); } function getCoins(){ var c = ""; var coinsDash = document.getElementById("coinsDash").innerText.split(" "); for(var i in coinsDash) c += coinsDash[i]; return parseInt(c); } function getTimeAlive(){ let secondsAlive = Math.round(((plrAlive ? Date.now() : deathTime) - timeJoin) / 1000), minutesAlive = 0, hoursAlive = 0; if(secondsAlive > 59){ minutesAlive = Math.floor(secondsAlive/60); secondsAlive -= minutesAlive * 60; } if(minutesAlive > 59){ hoursAlive = Math.floor(minutesAlive/60); minutesAlive -= hoursAlive * 60; } return hoursAlive + 'h ' + minutesAlive + 'min ' + secondsAlive + 's'; } function resetStats(){ topMass = 0; topLeaderboard = 1e5; timeJoin = Date.now(); xp = calcXp(); usedPowers = 0; coins = getCoins(); } const _fillText = CanvasRenderingContext2D.prototype.fillText; CanvasRenderingContext2D.prototype.fillText = function(text) { const match = text.toString().match(/^Mass: (\d+)$/); if(match){ var mass = parseInt(match[1]); if(mass > topMass) topMass = mass; } if(this.fillStyle == '#ffaaaa'){ if(parseInt(text) < topLeaderboard) topLeaderboard = parseInt(text); } _fillText.apply(this, arguments); } //Chat commands $('#chtbox').keydown(function (event) { if (event.keyCode === 13 && spawnedFirstTime) { var message = $('#chtbox').val(); switch(message){ case '/stats mass': $('#chtbox').val('Highest mass in this game: ' + topMass) break; case '/stats leaderboard': $('#chtbox').val('Highest leaderboard position in this game: ' + topLeaderboard) break; case '/stats xp': $('#chtbox').val('XP gained in this game: ' + (Math.floor(calcXp() - xp) > 0 ? Math.floor(calcXp() - xp) : 0 + 'XP')) break; case '/stats coins': $('#chtbox').val('Coins gained in this game: ' + (getCoins() - coins > 0 ? getCoins() - coins : "0")) break; case '/stats alive': $('#chtbox').val('Time alive: ' + getTimeAlive()) break; case '/stats powerups': $('#chtbox').val('Used Powerups in this game: ' + usedPowers) break; } } }); })();