[Neopets] Select Last X Items (Quick Stock Helper)

Adds options to quickly-er batch select items in quick stock. Goes from the last item because that's how I roll. ONLY SELECTS. DOUBLE CHECK YOUR OWN INPUTS BEFORE HITTING SUBMIT!

目前為 2023-03-20 提交的版本,檢視 最新版本

// ==UserScript==
// @name         [Neopets] Select Last X Items (Quick Stock Helper)
// @namespace    https://gf.qytechs.cn/en/scripts/447331
// @version      0.8
// @description  Adds options to quickly-er batch select items in quick stock. Goes from the last item because that's how I roll. ONLY SELECTS. DOUBLE CHECK YOUR OWN INPUTS BEFORE HITTING SUBMIT!
// @author       Piotr Kardovsky
// @match        http*://www.neopets.com/quickstock.phtml*
// @match        http*://neopets.com/quickstock.phtml*
// @icon         https://www.neopets.com//favicon.ico
// @grant        none
// @license      MIT
// ==/UserScript==

(function() {
    'use strict';
    const actions = ["Stock", "Deposit", "Donate", "Discard", "Gallery", "Closet", "Shed"];

    // Default amount. Simple enuff.
    const DEFAULT_AMOUNT = 10;

    // Default action. You can either use actions[x] where x = a number from 0 to 6, OR:
    // Choose 1 of the following. Make sure they're still in the quotes.
    // "Stock", "Deposit", "Donate", "Discard", "Gallery", "Closet", "Shed"
    const DEFAULT_ACTION = actions[1];

    window.addEventListener('load', () => {
        let qs = document.querySelector('form[name="quickstock"] table');
        // 3 is "magic", the header + check all + submit count as rows
        let rws = qs.rows.length - 3;
        //let nr = (rws - Math.floor(rws/20) + 1) % 20 === 0 ? rws - Math.floor(rws/20) + 1 : rws - Math.floor(rws/20);
        let items = qs.querySelectorAll('input[type="hidden"]');
        let ncsep = qs.querySelector('td[colspan="7"]');
        let npi = items.length; let nci = 0;
        if (ncsep != undefined && ncsep != null) {
            nci = Math.ceil(qs.querySelectorAll('input[type="radio"][name^="cash_radio_arr"]').length / 3);
        }

        // Amount
        let num = document.createElement('input');
        num.type = 'number';
        num.min = 0;
        num.max = 70;
        num.value = DEFAULT_AMOUNT;
        num.style.width = '38px';
        num.style.height = '22px';

        // Action
        let sty = document.createElement('select');
        sty.style.height = '28px';
        actions.forEach((i) => {
            let o = document.createElement('option');
            o.text = i;
            sty.add(o);
        });
        sty.value = DEFAULT_ACTION;

        // Button
        let dpb = document.createElement('button');
        dpb.innerText = 'Select!';
        dpb.style.height = '28px';
        dpb.addEventListener('click', (e) => {
            e.preventDefault();
            document.querySelector('form[name="quickstock"]').reset();
            if (parseInt(num.value) > parseInt(num.max)) num.value = num.max;
            for (let i = npi; i > npi - num.value; i--) {
                let itm = document.querySelector(`input[name^="radio_arr[${i}]"][value="${sty.value.toLowerCase()}"]`);
                if (itm != null && itm != undefined) {
                    if (itm.checked == false) itm.checked = true;
                }
            }
        });

        let container = document.createElement('div');
        let ic = document.createElement('span');
        npi != 1 ? ic.innerText = `${npi} items` : ic.innerText = `${npi} item`;
        nci != 1 ? ic.innerText += ` and ${nci} NC items.` : ic.innerText += ` and ${nci} NC item.`;

        container.classList.add('qsdc');
        container.innerHTML = "<strong>Select last: </strong>"
        container.append(num, sty, dpb, document.createElement('br'), ic);
        document.querySelector('.content').append(container);
    });
})();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址