Add action buttons to Neopets Quick Stock page
当前为
// ==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);