Neopets: Shop Wizard & Super Shop Wizard Results Image

Adds item image to SW & SSW results

当前为 2025-11-04 提交的版本,查看 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name             Neopets: Shop Wizard & Super Shop Wizard Results Image
// @namespace        kmtxcxjx
// @version          1.0.0
// @description      Adds item image to SW & SSW results
// @match            *://www.neopets.com/*
// @grant            none
// @run-at           document-end
// @icon             https://images.neopets.com/games/aaa/dailydare/2012/post/theme-icon.png
// @license          MIT
// ==/UserScript==

(async function() {
    'use strict';

    async function getImgSrc(itemId) {
        const res = await fetch(`https://itemdb.com.br/api/v1/items/many?item_id[]=${itemId}`, {
            method: 'GET',
        });
        const data = await res.json();
        return data[itemId].image;
    }

    async function handleSW() {
        const a = document.querySelector('div.wizard-results-grid a');
        if (!a) return;
        const match = a.href.match(/buy_obj_info_id=(\d+)/);
        if (!match) return;
        const itemId = match[1];

        const h3 = document.querySelector('div.wizard-results-text h3');
        if (!h3) return;

        let img = h3.nextElementSibling;
        if (!img || img.tagName.toLowerCase() !== 'img') {
            img = document.createElement('img');
            img.src = 'https://images.neopets.com/games/aaa/dailydare/2012/post/theme-icon.png';
            img.alt = itemId;
            img.style.width = '50px';
            h3.insertAdjacentElement('afterend', img);
        } else if (img && img.alt !== itemId) {
            img.src = '';
            img.alt = itemId;
        }
        const imgSrc = await getImgSrc(itemId);
        img.src = imgSrc;
    }

    async function handleNewSSW() {
        const a = document.querySelector('div#sswresults a');
        if (!a) return;
        const match = a.href.match(/buy_obj_info_id=(\d+)/);
        if (!match) return;
        const itemId = match[1];
        console.error(itemId);
    }

    async function handleOldSSW() {
        const a = document.querySelector('table#results_table a');
        if (!a) return;
        const match = a.href.match(/buy_obj_info_id=(\d+)/);
        if (!match) return;
        const itemId = match[1];
        console.error(itemId);
    }

    // Add mutation observers for all three SW variants
    if (window.location.href.includes('://www.neopets.com/shops/wizard.phtml')) {
        const shopWizardFormResults = document.querySelector('div#shopWizardFormResults');
        if (shopWizardFormResults) new MutationObserver(handleSW).observe(shopWizardFormResults, { childList: true, subtree: true });
    }
    const newSSW = document.querySelector('div#ssw__2020');
    if (newSSW) new MutationObserver(handleNewSSW).observe(newSSW, { childList: true, subtree: true });
    const oldSSW = document.querySelector('div#ssw_tabs_pane');
    if (oldSSW) new MutationObserver(handleOldSSW).observe(oldSSW, { childList: true, subtree: true });
})();