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 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==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);