One-Click Quickstock/Quickdeposit

Add action buttons to Neopets Quick Stock page

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

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

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

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

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

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

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name         One-Click Quickstock/Quickdeposit
// @description  Add action buttons to Neopets Quick Stock page
// @version      2025.06.25
// @license      GNU GPLv3
// @match        https://www.neopets.com/quickstock.phtml*
// @author       Posterboy + credit Max van Doorn for CSS styles
// @namespace    https://youtube.com/@Neo_Posterboy
// @icon         https://images.neopets.com/new_shopkeepers/t_1900.gif
// ==/UserScript==

(() => {
  'use strict';

  // Load external CSS
  document.head.appendChild(Object.assign(document.createElement('link'), {
    rel: 'stylesheet',
    href: 'https://greasyfork.org/scripts/540710-neopets-2020/code/neopets_2020.user.css'
  }));

  const applyButtonStyles = (btn, extraStyles = {}) => {
    btn.style.fontSize = 'x-large';
    btn.style.paddingLeft = '20px';
    btn.style.paddingRight = '20px';
    Object.entries(extraStyles).forEach(([k, v]) => btn.style[k] = v);
  };

  window.addEventListener('load', () => setTimeout(createToolbar, 2000));

  function selectAction(action) {
    document.querySelectorAll(`input[type="radio"][value="${action}"]`).forEach(r => r.checked = true);
    const form = document.querySelector('form[name="quickstock"]');
    if (form) form.submit();
  }

  function createToolbar() {
    if (document.querySelector('#custom-toolbar')) return;

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

    const toolbar = document.createElement('div');
    toolbar.id = 'custom-toolbar';
    toolbar.style.paddingBottom = '10px';
    toolbar.style.textAlign = 'center';

    const stockAllBtn = document.createElement('button');
    stockAllBtn.textContent = 'Stock All';
    stockAllBtn.type = 'button';
    stockAllBtn.classList.add('button-green__2020');
    applyButtonStyles(stockAllBtn, { marginRight: '10px' });
    stockAllBtn.onclick = () => selectAction('stock');

    const depositAllBtn = document.createElement('button');
    depositAllBtn.textContent = 'Deposit All';
    depositAllBtn.type = 'button';
    depositAllBtn.classList.add('button-blue__2020');
    applyButtonStyles(depositAllBtn);
    depositAllBtn.onclick = () => selectAction('deposit');

    toolbar.append(stockAllBtn, depositAllBtn);

    const table = form.querySelector('table');
    if (table) {
      table.parentNode.insertBefore(toolbar, table);
    } else {
      form.insertBefore(toolbar, form.firstChild);
    }
  }
})();