Memory Pair AutoSolver

Автоматически решает игру "Найди пару" на remanga.org (Shift+T для запуска, выводит время работы)

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

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

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

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

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

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.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==UserScript==
// @name         Memory Pair AutoSolver
// @namespace    https://remanga.org/
// @version      1.1
// @description  Автоматически решает игру "Найди пару" на remanga.org (Shift+T для запуска, выводит время работы)
// @match        https://remanga.org/*
// @grant        none
// @license      GNU AGPLv3
// ==/UserScript==

(function() {
    'use strict';

    let openedCards = {};
    let solving = false;
    let interval;
    let startTime;

    function solveGame() {
        let cards = document.querySelectorAll("button img[alt='card']");

        // проверяем, есть ли ещё закрытые карты
        let closedCards = Array.from(cards).filter(img => img.getAttribute("src").includes("random-card.webp"));
        if (closedCards.length === 0) {
            clearInterval(interval);
            solving = false;
            let endTime = performance.now();
            console.warn("Игра решена за " + ((endTime - startTime) / 1000).toFixed(2) + " секунд");
            return;
        }

        cards.forEach((img, idx) => {
            let card = img.closest("button");
            let src = img.getAttribute("src");

            if (src.includes("random-card.webp")) {
                card.click();

                setTimeout(() => {
                    let newSrc = img.getAttribute("src");

                    if (!newSrc.includes("random-card.webp")) {
                        if (openedCards[newSrc] !== undefined) {
                            let pairIdx = openedCards[newSrc];
                            let pairCard = cards[pairIdx].closest("button");

                            pairCard.click();
                            card.click();
                        } else {
                            openedCards[newSrc] = idx;
                        }
                    }
                }, 0);
            }
        });
    }

    document.addEventListener('keydown', function(e) {
        if (e.shiftKey && e.code === 'KeyT') {
            if (!solving) {
                solving = true;
                openedCards = {};
                startTime = performance.now(); // начало отсчёта
                interval = setInterval(solveGame, 0);
                console.warn("AutoSolver запущен");
            }
        }
    });
})();