Neopets: Quick Stock Pricer

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

Bu betiği kurabilmeniz için Tampermonkey, Greasemonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği yüklemek için Tampermonkey gibi bir uzantı yüklemeniz gerekir.

Bu betiği kurabilmeniz için Tampermonkey ya da Violentmonkey gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği kurabilmeniz için Tampermonkey ya da Userscripts gibi bir kullanıcı betiği eklentisini kurmanız gerekmektedir.

Bu betiği indirebilmeniz için ayrıca Tampermonkey gibi bir eklenti kurmanız gerekmektedir.

Bu komut dosyasını yüklemek için bir kullanıcı komut dosyası yöneticisi uzantısı yüklemeniz gerekecek.

(Zaten bir kullanıcı komut dosyası yöneticim var, kurmama izin verin!)

Bu stili yüklemek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için Stylus gibi bir uzantı kurmanız gerekir.

Bu stili yükleyebilmek için Stylus gibi bir uzantı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

Bu stili yüklemek için bir kullanıcı stili yöneticisi uzantısı kurmanız gerekir.

Bu stili yükleyebilmek için bir kullanıcı stili yöneticisi uzantısı yüklemeniz gerekir.

(Zateb bir user-style yöneticim var, yükleyeyim!)

// ==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});
})();