Memory Pair AutoSolver

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==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 запущен");
            }
        }
    });
})();