Strudels

Neopets SDB Auto Bulk Selectinator

May 27th, 2026 (edited)
221
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name         Neopets SDB Auto Bulk Selectinator
  3. // @namespace    http://tampermonkey.net/
  4. // @version      2026-05-31
  5. // @description  Autoselects items in SDB for bulk movement when you input a quantity. Also allows you to press Enter to submit actions or PIN instead of having to click Confirm
  6. // @author       Rippy
  7. // @match        http*://*.neopets.com/safetydeposit.phtml*
  8. // @icon         https://www.google.com/s2/favicons?sz=64&domain=neopets.com
  9. // @grant        none
  10. // ==/UserScript==
  11.  
  12. (function() {
  13.     'use strict';
  14.  
  15.     // Note: Mostly intended for the list view. Shouldn't break the grid view, but doesn't really add anything to it.
  16.  
  17.     // when sdb items load, we append a hidden init attribute to the first item row during setupBehaviour()
  18.     // this init value is checked for in the mutationobserver before running setupBehaviour() to ensure the init hasn't been run yet
  19.     // this way we can prevent stacking a ton of duplicate event handlers whenever there's a mutation on the current sdb page
  20.     // while also allowing the mutationobserver to keep running to check for sdb page changes etc.
  21.     // which will naturally wipe the init value and allow setupBehaviour() to run again on all the new item rows
  22.     const checkInit = () => {
  23.         const row = $(".sdb-row-odd")[0];
  24.         return !!$(row).attr("init");
  25.     }
  26.     const setupBehaviour = () => {
  27.         $(".np-stepper-input").keyup((e) => {
  28.             const qty = parseInt($(e.target).val()) || 0;
  29.             const itemCheckbox = $(e.target).parent().parent().parent().find(".sdb-item-checkbox")[0];
  30.             if (!$(itemCheckbox).is(":checked") && qty > 0) {
  31.                 $(itemCheckbox).click();
  32.             }
  33.         });
  34.         $(".np-stepper-btn").on("click", (e) => {
  35.             $(e.target).parent().find(".np-stepper-input")[0].dispatchEvent(new Event("keyup"));
  36.         });
  37.         const row = $(".sdb-row-odd")[0];
  38.         $(row).attr("init", true);
  39.     };
  40.     $(document).keypress((e) => {
  41.         const key = e.which;
  42.         if (key == 13) { // when pressing enter
  43.             if ($(".sdb-confirm-body input[type=password]").length) { // if the PIN prompt is active
  44.                 const button = $("#sdb__popup > .popup-footer__2020 > div > .np-button")[1];
  45.                 if (button && $(button).text() === "Confirm") {
  46.                     $(button).click();
  47.                 }
  48.             }
  49.             else if ($(".sdb-drawer").length) { // if the bulk action footer is active
  50.                 const dropdown = $(".sdb-drawer > .sdb-drawer-content > .sdb-drawer-action-row > .sdb-as > .sdb-action-select")[0];
  51.                 if ($(dropdown).val()) { // user has selected an action
  52.                     const button = $(".sdb-drawer > .sdb-drawer-content > .sdb-drawer-buttons > .np-button")[1];
  53.                     if (button && $(button).text() === "Confirm") {
  54.                         $(button).click();
  55.                     }
  56.                 }
  57.             }
  58.         }
  59.     });
  60.     const interval = setInterval(() => {
  61.         // this suuuuuuucks but mutationobserver occasionally fails to fire properly on the vue app's initial load when the sdb window/tab is not in focus and i have no idea what to do about it
  62.         // so this is just a failsafe for initial app load
  63.         if ($(".np-stepper-input").length) {
  64.             console.log("Interval setup");
  65.             if (!checkInit()) {
  66.                 setupBehaviour();
  67.             }
  68.             clearInterval(interval);
  69.         }
  70.     }, 200);
  71.     const observer = new MutationObserver(() => {
  72.         console.log("Observer triggered");
  73.         if (!checkInit()) {
  74.             setupBehaviour();
  75.         }
  76.     });
  77.     observer.observe(document.querySelector("#sdb-vue-app"), {childList: true, subtree: true});
  78. })();
Advertisement
Add Comment
Please, Sign In to add comment