Gates of Survival - Hide "Eat" Button

Hides the "Eat Another X" button when the screen already reports that you have zero of X left. Also hides the button if your health is already full.

目前為 2016-06-22 提交的版本,檢視 最新版本

// ==UserScript==
// @namespace       dex.gos
// @name            Gates of Survival - Hide "Eat" Button
// @description     Hides the "Eat Another X" button when the screen already reports that you have zero of X left. Also hides the button if your health is already full.
// @include         http://www.gatesofsurvival.com/game/index.php?page=main
// @grant           none
// @version         1.0
// ==/UserScript==

// The game does everything by AJAX requests, so the standard way to make the script only run on certain pages doesn't apply. Use this to hook into each AJAX call and make the
// script run each time the correct "page" loads.
function callbackIfPageMatched(matchUrl, callback) {
    $(document).ajaxSuccess(
        function(event, xhr, settings) {
            if (settings.url == matchUrl) {
                // Wait 250 milliseconds before calling the function so that the page has hopefully had time to update.
                window.setTimeout(callback, 250);
            }
        }
    );
}

function eatLogic() {
    var hideButton = false;
    
    // Get the html of the "page" as a string.
    var pageContent = $("#page > center").html();
    // Look for the amount of food item remaining.
    var resultsArry = pageContent.match(/still have <b>(\d*,?\d+).*?<\/b> remaining/i);
    if (resultsArry[1] == 0) {
        // None of this food is left.
        hideButton = true;
    }
    
    // Also check for full health.
    var resultsArry = pageContent.match(/<b>Current Health<\/b>:\s*(\d+)\s*\/\s*(\d+)/i);
    var curHlth = parseInt(resultsArry[1].replace(/,/g, ""), 10);
    var maxHlth = parseInt(resultsArry[2].replace(/,/g, ""), 10);
    if (curHlth >= maxHlth) {
        // Health is full
        hideButton = true;
    }
    
    if (hideButton) {
        // Either there is no food left, or the player's health is full. Either way, hide the "Eat another X" button.
        var btn = $("#page > center > #form");
        btn.remove();
    }
}

callbackIfPageMatched("heal.php", eatLogic);