Neopets: Quick Stock Pricer

Adds itemDB prices to your Quick Stock page. Updated for the API changes and the new Quick Stock!

이 스크립트를 설치하려면 Tampermonkey, Greasemonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램을 설치해야 합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Violentmonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey 또는 Userscripts와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 Tampermonkey와 같은 확장 프로그램이 필요합니다.

이 스크립트를 설치하려면 유저 스크립트 관리자 확장 프로그램이 필요합니다.

(이미 유저 스크립트 관리자가 설치되어 있습니다. 설치를 진행합니다!)

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 Stylus와 같은 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

이 스타일을 설치하려면 유저 스타일 관리자 확장 프로그램이 필요합니다.

(이미 유저 스타일 관리자가 설치되어 있습니다. 설치를 진행합니다!)

// ==UserScript==
// @name         Neopets: Quick Stock Pricer
// @namespace    https://github.com/saahphire/NeopetsUserscripts
// @version      1.4.0
// @description  Adds itemDB prices to your Quick Stock page. Updated for the API changes and the new Quick Stock!
// @author       saahphire
// @homepageURL  https://github.com/saahphire/NeopetsUserscripts
// @homepage     https://github.com/saahphire/NeopetsUserscripts
// @match        *://*.neopets.com/quickstock.phtml*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=neopets.com
// @license      Unlicense
// @require      https://update.greatest.deepsurf.us/scripts/567036/1759045/itemDB%20Fetch%20Lib.js
// ==/UserScript==

/*
•:•.•:•.•:•:•:•:•:•:•:••:•.•:•.•:•:•:•:•:•:•:•:•.•:•.•:•:•:•:•:•:•:••:•.•:•.•:•.•:•:•:•:•:•:•:•:•.•:•:•.•:•.••:•.•:•.••:
........................................................................................................................
☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦
    The other Quick Stock Pricer isn't updated for itemDB's API changes yet, meaning it'll stop working soon.
    This script adds prices to a new line in each item name, sourced by itemDB. Please keep in mind you must open itemDB
    at least once every 24h (without logging in) or 14 days (logging in) in the same device you use this userscript in.
    This is due to their API policies, that have changed in March 2026.

    https://itemdb.com.br/contribute

    ✦ ⌇ saahphire
☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦ ⠂⠄⠄⠂⠁⠁⠂⠄⠂⠄⠄⠂☆ ⠂⠄⠄⠂⠁⠁⠂⠄⠄⠂✦
........................................................................................................................
•:•.•:•.•:•:•:•:•:•:•:••:•.•:•.•:•:•:•:•:•:•:•:•.•:•.•:•:•:•:•:•:•:••:•.•:•.•:•.•:•:•:•:•:•:•:•:•.•:•:•.•:•.••:•.•:•.••:
*/

const getItemName = (cell) => cell.childNodes[0].childNodes[0].textContent;

const addInfoToCell = (info) => {
    const p = document.createElement('p');
    if(info.price?.value) {
        p.textContent = `${info.price.value.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",")} NP`;
        p.dataset.price = info.price.value;
        p.title = new Date(info.price.addedAt).toLocaleString();
        if(info.price.inflated) p.classList.add('saahphire-quickstockpricer-inflated');
    }
    else {
        p.textContent = 'No price found';
        console.log('Couldn\'t find a price in', info);
    }
    if(info.saleStatus) p.classList.add(`saahphire-quickstockpricer-${info.saleStatus.status}`);
    return p;
}

const css = `<style>
.saahphire-quickstockpricer-hts, .saahphire-quickstockpricer-ets, .saahphire-quickstockpricer-regular {
    margin: 0;
    &::after {
        font-weight: 600;
        font-size: 0.8em;
        margin-left: 1em;
    }
}
.saahphire-quickstockpricer-hts::after {
    content: "HTS";
    color: red;
}
.saahphire-quickstockpricer-ets::after {
    content: "ETS";
    color: green;
}
</style>`;

const init = async () => {
    const cells = document.querySelectorAll('tr:not(:last-child) td.text-left:first-child');
    const names = [...cells].map(getItemName);
    if(!names.length) return;
    window.postMessage('Saahphire Quick Stock Pricer here');
    const response = await fetch(`https://itemdb.com.br/api/v1/items/many?name[]=${names.join('&name[]=')}`, {credentials: 'include'});
    const items = await response.json();
    cells.forEach(cell => cell.appendChild(addInfoToCell(items[getItemName(cell)])));
    document.head.insertAdjacentHTML('beforeend', css);
}

(function() {
    'use strict';
    const observer = new MutationObserver(init);
    observer.observe(document.querySelector('#quickstock-app > div'), {childList: true});
})();