// ==UserScript== // @name Agma.io stats // @namespace http://tampermonkey.net/ // @version 0.1.0 // @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; var level = 0; //insert values function stats(){ 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; let timeAlive = getTimeAlive(); 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 : "/"; document.getElementById('timeAlive').innerText = timeAlive; document.getElementById('powsUsed').innerText = usedPowers; plrAlive = false; } //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; 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((Date.now() - 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 let cmds = { 1: {cmd: '/stats mass', msg: 'Highest mass in this game: ' + topMass }, 2: { cmd: '/stats leaderboard', msg: 'Highest leaderboard position in this game: ' + topLeaderboard }, 3: { cmd: '/stats xp', msg: 'XP gained in this game: ' + (Math.floor(calcXp() - xp) > 0 ? Math.floor(calcXp() - xp) : 0 + 'XP') }, 4: { cmd: '/stats coins', msg: 'Coins gained in this game: ' + (getCoins() - coins > 0 ? getCoins() - coins : "0") }, 5: { cmd: '/stats alive', msg: 'Time alive: ' + getTimeAlive() }, 6: { cmd: '/stats powerups', msg: 'Used Powerups in this game: ' + usedPowers }, 7: { cmd: '/stats test', msg: 'test' } }; $('#chtbox').keydown(function (event) { if (event.keyCode === 13) { var message = $('#chtbox').val(); for(var i = 1; i <= Object.keys(cmds).length; i++){ if(message == cmds[i].cmd){ console.log(cmds[i].msg) $('#chtbox').val(cmds[i].msg) } } } }); */ })();