One-Click Quickstock/Quickdeposit

Add action buttons to Neopets Quick Stock page

目前為 2025-01-30 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

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

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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();
    });
})();