Neopets - Tyranu Evavu Autoplayer

Autoplays Tyranu Evavu

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         Neopets - Tyranu Evavu Autoplayer
// @version      1.3
// @namespace    https://greasyfork.org/en/users/1450608-dogwithglasses
// @description  Autoplays Tyranu Evavu
// @match        *://www.neopets.com/games/tyranuevavu.phtml*
// @grant        GM_getValue
// @grant        GM_setValue
// @grant        GM_deleteValue
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';

    const fullDeck = (() => {
        const suits = ["hearts", "clubs", "diamonds", "spades"];
        const cards = [];
        for (let val = 2; val <= 14; val++) {
            for (let suit of suits) {
                cards.push(`${val}_${suit}`);
            }
        }
        return cards;
    })();

    const getCardList = () => JSON.parse(GM_getValue("cards", "[]"));
    const setCardList = (cards) => GM_setValue("cards", JSON.stringify(cards));

    function main() {
        const playBtn = document.querySelector('form input[type="submit"][value="Play Now!"]');
        const replayBtn = document.querySelector('input[type="submit"][value="Play Again"]');
        const cardImg = document.querySelector('img[src*="/games/cards/"]');

        const buttonsFound = playBtn || replayBtn || cardImg;

        if (!buttonsFound && !document.body.innerHTML.includes("I think that means you've played enough for today.")) {
            location.reload();
            return;
        }

        if (playBtn) {
            setCardList(fullDeck);
            playBtn.closest("form").submit();
        } else if (replayBtn) {
            GM_deleteValue("cards");
            replayBtn.closest("form").submit();
        } else if (cardImg) {
            const url = cardImg.src;
            const match = url.match(/cards\/(.+)\.gif/);
            if (match) {
                const currentCard = match[1];
                const deck = getCardList();
                const index = deck.indexOf(currentCard);
                const total = deck.length;
                if (index !== -1) deck.splice(index, 1);
                setCardList(deck);

                if (total > 1) {
                    const ratio = index / (total - 1);
                    const action = ratio > 0.5 ? "lower" : "higher";
                    const link = document.querySelector(`a[href*="action=${action}"]`);
                    if (link) {
                        link.click();
                    }
                }
            }
        }
    }

    setTimeout(main, Math.floor(Math.random() * 800) + 200);

})();