One-Click Quickstock/Quickdeposit

Add action buttons to Neopets Quick Stock page

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

您需要先安裝使用者腳本管理器擴展,如 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.31
// @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==

// Main function to handle Stock and Deposit actions
function selectAction(action) {
    console.log(`selectAction called with action: ${action}`);

    // Find all radio buttons on the page
    let radios = document.querySelectorAll(`input[type="radio"][value="${action}"]`);

    // Loop through each radio button and select it
    radios.forEach(radio => {
        radio.checked = true;
    });

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

// Create toolbar with "Stock All" and "Deposit All" buttons
function createToolbar() {
    let existingToolbar = document.querySelector('#custom-toolbar');
    if (existingToolbar) return;

    let form = document.querySelector('form[name="quickstock"]');
    if (!form) return;

    // Create toolbar div
    let toolbar = document.createElement('div');
    toolbar.id = 'custom-toolbar';
    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 toolbar
    toolbar.appendChild(stockAllBtn);
    toolbar.appendChild(depositAllBtn);

    // Insert the toolbar above the table
    let table = form.querySelector('table');
    table.parentNode.insertBefore(toolbar, table);
}

// Initialize toolbar after window load
window.addEventListener('load', createToolbar);