Agma.io stats

See stats about your game in the death screen!

Από την 08/03/2021. Δείτε την τελευταία έκδοση.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey, το Greasemonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Violentmonkey για να εγκαταστήσετε αυτόν τον κώδικα.

θα χρειαστεί να εγκαταστήσετε μια επέκταση όπως το Tampermonkey ή το Userscripts για να εγκαταστήσετε αυτόν τον κώδικα.

You will need to install an extension such as Tampermonkey to install this script.

Θα χρειαστεί να εγκαταστήσετε μια επέκταση διαχείρισης κώδικα χρήστη για να εγκαταστήσετε αυτόν τον κώδικα.

(Έχω ήδη έναν διαχειριστή κώδικα χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Έχω ήδη έναν διαχειριστή στυλ χρήστη, επιτρέψτε μου να τον εγκαταστήσω!)

// ==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
// ==/UserScript==

(function() {
    const ad = document.getElementById("zoomItem");
    const sexyStats = document.createElement("div");
    sexyStats.innerHTML =`
<div>
<style type="text/css">input:focus {
    outline: 0;
}

#statsContainer {
    width: 40%;
    height: 40%;
    position: fixed;
    color: 44B3D3;
    background-color: #525765;
    border-radius: 3px;
    -webkit-box-shadow: 0 0 7px 2px #3f434e inset;
    -moz-box-shadow: 0 0 7px 2px #2e3138 inset;
    box-shadow: 0 0 7px 2px #2e3138 inset;
    margin-top: 20px;
}

.statsTable {
    text-align: center;
    padding-left: 6px;
    border-spacing: 50% 0;
    white-space: nowrap;
    overflow-x: hidden;
    text-overflow: ellipsis;
    width: 40%;
}

#statsTitle {
    text-align: center;
    margin-left: 0%;
    color: #337AB7;
}

.statsDescrip {
    color: #FDFDFD;
}

.statsNumb {
    color: #BFBFC0;
    padding-bottom: 5px;
}

#statsTable {
    text-align: center;
    padding: 20px;
    margin-left: 11.5%;
    margin-top: 10px;
}

div[style*="width: 100%; margin-left: 10%;"] {
    margin-top: 5px;
}

</style>

<div id="statsContainer">
<div>
<h1 id="statsTitle"><b>Gameplay Stats</b></h1>
<table id="statsTable">
<tbody id="statsBody">
<tr>
<th class="statsTable statsDescrip">Highest Mass</th>
<th class="statsTable statsDescrip">Top Leaderboard</th>
</tr>
<tr>
<td class="statsTable statsNumb" id="highestMass">/</td>
<td class="statsTable statsNumb" id="topLeader">/</td>
</tr>
<tr>
<th class="statsTable statsDescrip">XP Gained</th>
<th class="statsTable statsDescrip">Coins Gained</th>
</tr>
<tr>
<td class="statsTable statsNumb" id="xpGain">0 | 0%</td>
<td class="statsTable statsNumb" id="coinGain">0</td>
</tr>
<tr>
<th class="statsTable statsDescrip">Time Alive</th>
<th class="statsTable statsDescrip">Powerups Used</th>
</tr>
<tr>
<td class="statsTable statsNumb" id="timeAlive">0h 0min 0s</td>
<td class="statsTable statsNumb" id="powsUsed">0</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
`
    ad.parentNode.replaceChild(sexyStats, ad);
    document.getElementById("featuredButtons").parentElement.style.marginTop = "5px";
    document.getElementById("advertDialog1").style.opacity = "0";
    var plrAlive = false;
    var level = 0;
    //insert values
    function stats(){
        document.getElementById("agmaAdHref").removeAttribute("href");
        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 : "/")
        },
        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)
                }
            }
        }
    });
    */
})();