Add action buttons to Neopets Quick Stock page
当前为
// ==UserScript==
// @name Neopets Quick Stock Extra Buttons
// @version 0.4
// @description Add action buttons to Neopets Quick Stock page
// @match https://www.neopets.com/quickstock.phtml*
// @icon https://images.neopets.com/new_shopkeepers/t_1900.gif
// @author Posterboy
// @namespace https://greasyfork.org/users/1277376
// @grant none
// ==/UserScript==
(function() {
'use strict';
function createToolbar() {
let form = document.querySelector('form[name="quickstock"]');
if (!form) return;
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';
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');
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');
toolbar.appendChild(stockAllBtn);
toolbar.appendChild(depositAllBtn);
let table = form.querySelector('table');
table.parentNode.insertBefore(toolbar, table);
}
function selectAction(action) {
let radios = document.querySelectorAll(`input[name^="radio_arr"]`);
radios.forEach(radio => {
if (radio.value === action) {
radio.checked = true;
}
});
document.querySelector('form[name="quickstock"]').submit();
}
window.addEventListener('load', createToolbar);
})();