One-Click Quickstock/Quickdeposit

Add action buttons to Neopets Quick Stock page

当前为 2025-01-30 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name         One-Click Quickstock/Quickdeposit
// @description  Add action buttons to Neopets Quick Stock page
// @version      2025.01.30
// @license      GNU GPLv3
// @match        https://www.neopets.com/quickstock.phtml*
// @author       Posterboy
// @namespace    https://youtube.com/@Neo_Posterboy
// @icon         https://images.neopets.com/new_shopkeepers/t_1900.gif
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    // ==============================
    // User Interface
    // ==============================

    function createToolbar() {
        console.log("createToolbar called");
        let form = document.querySelector('form[name="quickstock"]');
        if (!form) {
            console.log("Form not found");
            return;
        }
        console.log("Form found");

        // Create a toolbar div
        let toolbar = document.createElement('div');
        toolbar.style.marginBottom = '15px';
        toolbar.style.padding = '10px';
        toolbar.style.backgroundColor = '#f4f4f4';
        toolbar.style.border = '1px solid #ddd';
        toolbar.style.borderRadius = '5px';
        toolbar.style.boxShadow = '0 2px 5px rgba(0, 0, 0, 0.1)';
        toolbar.style.textAlign = 'center';

        // Create "Stock All" button
        let stockAllBtn = document.createElement('button');
        stockAllBtn.textContent = 'Stock All';
        stockAllBtn.style.padding = '10px 20px';
        stockAllBtn.style.marginRight = '10px';
        stockAllBtn.style.backgroundColor = '#4CAF50';
        stockAllBtn.style.color = 'white';
        stockAllBtn.style.border = 'none';
        stockAllBtn.style.borderRadius = '4px';
        stockAllBtn.style.cursor = 'pointer';
        stockAllBtn.type = 'button';
        stockAllBtn.onclick = () => selectAction('stock');

        // Create "Deposit All" button
        let depositAllBtn = document.createElement('button');
        depositAllBtn.textContent = 'Deposit All';
        depositAllBtn.style.padding = '10px 20px';
        depositAllBtn.style.backgroundColor = '#2196F3';
        depositAllBtn.style.color = 'white';
        depositAllBtn.style.border = 'none';
        depositAllBtn.style.borderRadius = '4px';
        depositAllBtn.style.cursor = 'pointer';
        depositAllBtn.type = 'button';
        depositAllBtn.onclick = () => selectAction('deposit');

        // Append buttons to the toolbar
        toolbar.appendChild(stockAllBtn);
        toolbar.appendChild(depositAllBtn);

        // Insert the toolbar above the table
        let table = form.querySelector('table');
        if (!table) {
            console.log("Table not found");
            return;
        }
        table.parentNode.insertBefore(toolbar, table);
        console.log("Toolbar added");
    }

    // ==============================
    // Script function
    // ==============================

    function selectAction(action) {
        console.log(`selectAction called with action: ${action}`);

        // Find all rows in the table (excluding header and empty rows)
        let rows = document.querySelectorAll('table tr');

        //Function to help deposit NC items since they don't have a Stock radio button
        rows.forEach(row => {
            let stockCell = row.cells[1];

            if (!stockCell) return;

            // Skip rows with N/A only if the action is "stock"
            if (action === 'stock' && stockCell.textContent.trim() === 'N/A') {
                console.log('Skipping item with N/A in Stock for Stock action');
                return;
            }

            // Otherwise, look for the radio button in the row for the selected action
            let radio = row.querySelector(`input[name^="cash_radio_arr"][value="${action}"]`);

            if (radio) {
                console.log(`Selecting radio button for action: ${action} on item`);
                radio.checked = true;
            } else {
                console.log(`No radio button found for action: ${action} on item`);
            }
        });

        // After all items are processed, submit the form
        let form = document.querySelector('form[name="quickstock"]');
        if (form) {
            console.log("Submitting form");
            form.submit();
        } else {
            console.log("Form not found when submitting");
        }
    }

    window.addEventListener('load', () => {
        console.log("Window loaded");
        createToolbar();
    });
})();