[Neopets] Jellyneo Trade Matcher

Compare users between "Up For Trade" and "Seeking" lists on Jellyneo.

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         [Neopets] Jellyneo Trade Matcher
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Compare users between "Up For Trade" and "Seeking" lists on Jellyneo.
// @author       BandanaWaddleDee24
// @match        *://items.jellyneo.net/item/*/uft-list/
// @grant        none
// @license MIT
// ==/UserScript==

(function () {
    'use strict';

    function getUFTUsers() {
        const rows = document.querySelectorAll('table tbody tr td:first-child');
        return Array.from(rows).map(row => row.textContent.trim());
    }

    function findMatches(uftUsers, seekingUsers) {
        const matches = uftUsers.filter(user => seekingUsers.includes(user));
        return matches;
    }

    function addCompareButton() {
        const titleElement = document.querySelector('h1'); 
        if (!titleElement) return;

        const button = document.createElement('button');
        button.textContent = '🔍 Check Matches';
        button.style.marginTop = '10px';
        button.style.marginLeft = '10px';
        button.style.padding = '10px 15px';
        button.style.backgroundColor = '#007BFF';
        button.style.color = 'white';
        button.style.border = 'none';
        button.style.borderRadius = '5px';
        button.style.cursor = 'pointer';
        button.style.fontSize = '14px';

        button.addEventListener('click', async () => {
            const seekingUrl = prompt('Enter the URL of your "Seeking" list:');

            if (!seekingUrl) {
                alert('You need to provide the URL of your "Seeking" list!');
                return;
            }

            try {
                const seekingResponse = await fetch(seekingUrl);

                if (!seekingResponse.ok) {
                    alert('Failed to fetch the Seeking list. Please check the URL and try again.');
                    return;
                }

                const seekingHtml = await seekingResponse.text();
                const parser = new DOMParser();
                const seekingDoc = parser.parseFromString(seekingHtml, 'text/html');

                const uftUsers = getUFTUsers();
                const seekingUsers = Array.from(seekingDoc.querySelectorAll('table tbody tr td:first-child')).map(el => el.textContent.trim());

                const matches = findMatches(uftUsers, seekingUsers);

                if (matches.length > 0) {
                    alert(`Matches found:\n\n${matches.join('\n')}`);
                } else {
                    alert('No matches found.');
                }
            } catch (error) {
                console.error('An error occurred:', error);
                alert('Could not fetch the list. Please check the URL and try again.');
            }
        });

        titleElement.parentElement.insertBefore(button, titleElement.nextSibling);
    }

    addCompareButton();
})();