// ==UserScript==
// @name         A Mining Game: Fix minor issues
// @namespace    https://github.com/Phylogenesis/
// @version      0.2.3
// @description  Fixes some minor issues with the chat system and allows manual saving by clicking on the button in the top right
// @author       Luke Jones
// @include      /^http://trugul\.com/(index\.php)?$/
// @grant        none
// @downloadURL  https://github.com/Phylogenesis/greasemonkey/raw/master/AMGFixes.user.js
// ==/UserScript==

(function ($) {
    var AGame = {
        client:     undefined,
        username:   undefined,
        lastSubmit: undefined,
    };
    
    function updateRanks() {
        $.ajax({
            url:     'http://trugul.com/highscores/',
            async:   true,
            success: function (data) {
                var matches = /You are ranked #(\d+)/.exec(data);
                var rank = 'N/A'
                
                if (matches.length > 0) {
                    rank = matches[1];
                }
                
                $('#leaderboardRanking span.mainRank').text(rank);
            }
        });
        
        $.ajax({
            url:     'http://trugul.com/highscores/?order=prestige',
            async:   true,
            success: function (data) {
                var matches = /You are ranked #(\d+)/.exec(data);
                var rank = 'N/A'
                
                if (matches.length > 0) {
                    rank = matches[1];
                }
                
                $('#leaderboardRanking span.prestigeRank').text(rank);
            }
        });
    };
    
    $(document).on(
        'click',
        'div.tabs a',
        function () {
            setTimeout(
                function () {
                    if ($('div.chat-room-message-container:visible').length > 0) {
                        $('div.chat-room-message-container').scrollTop($('div.chat-room-message-container')[0].scrollHeight);
                        $('body').css('padding-bottom', $('div.popout').outerHeight() + 'px');
                    } else {
                        $('body').css('padding-bottom', '20px');
                    }
                },
                100
            );
        }
    );

    $(document).on(
        'click',
        'ul.navbar-right a',
        function (e) {
            if (AGame.client) {
                AGame.client.emit('save');
            }
            
            e.preventDefault();
        }
    );
    
    setTimeout(function () {
        AGame.client   = io('http://5.189.137.117:469');
        AGame.username = $('#playerName').text();
            
        AGame.client.on(
            'gameVars',
            function (data) {
                var lastSubmit = data.gameVars.lastSubmit;
                
                if (AGame.lastSubmit !== lastSubmit) {
                    AGame.lastSubmit = lastSubmit;
                    updateRanks();
                }
            }
        );
        
        $('#quickdetails tr').prepend('<td id="leaderboardRanking" class="displaytext2"><b>Ranking</b><br><span class="mainRank">&hellip;</span><span class="prestigeRank">&hellip;</span></td>');
        
        $('#leaderboardRanking').css({
            textAlign: 'center',
            padding:   0
        });
        
        $('#leaderboardRanking span').css({
            display:    'inline-block',
            width:      '50px',
            cursor:     'pointer',
            lineHeight: '22px'
        });
        
        $('span.mainRank').css({
            borderRight:            '1px solid white',
            borderBottomLeftRadius: '5px'
        });

        $('span.prestigeRank').css({
            borderBottomRightRadius: '5px'
        });
        
        $('#leaderboardRanking span').hover(
            function () { $(this).css('background-color', '#8b8'); },
            function () { $(this).css('background-color', ''); }
        );

        $('span.mainRank').click(function () {
            window.open('http://trugul.com/highscores/?user=' + AGame.username)
        });

        $('span.prestigeRank').click(function () {
            window.open('http://trugul.com/highscores/?order=prestige&user=' + AGame.username)
        });
    }, 5000);
})(jQuery);
    

@@ -3085,12 +3085,8 @@
 /b%3E%3C
-br%3E%3C
 span
@@ -3165,24 +3165,24 @@
 an%3E%3C/td%3E');%0A
+
         %0A   
@@ -3288,32 +3288,207 @@
    %7D);%0A        %0A
+        $('#leaderboardRanking b').css(%7B%0A            display:      'block',%0A            borderBottom: '1px solid white',%0A            lineHeight:   '18px'%0A        %7D);%0A        %0A
         $('#lead
@@ -3651,10 +3651,10 @@
 t: '
-22
+19
 px'%0A

Update AMGFixes.user.js