Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // ==UserScript==
- // @name Neopets SDB Auto Bulk Selectinator
- // @namespace http://tampermonkey.net/
- // @version 2026-05-31
- // @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
- // @author Rippy
- // @match http*://*.neopets.com/safetydeposit.phtml*
- // @icon https://www.google.com/s2/favicons?sz=64&domain=neopets.com
- // @grant none
- // ==/UserScript==
- (function() {
- 'use strict';
- // Note: Mostly intended for the list view. Shouldn't break the grid view, but doesn't really add anything to it.
- // when sdb items load, we append a hidden init attribute to the first item row during setupBehaviour()
- // this init value is checked for in the mutationobserver before running setupBehaviour() to ensure the init hasn't been run yet
- // this way we can prevent stacking a ton of duplicate event handlers whenever there's a mutation on the current sdb page
- // while also allowing the mutationobserver to keep running to check for sdb page changes etc.
- // which will naturally wipe the init value and allow setupBehaviour() to run again on all the new item rows
- const checkInit = () => {
- const row = $(".sdb-row-odd")[0];
- return !!$(row).attr("init");
- }
- const setupBehaviour = () => {
- $(".np-stepper-input").keyup((e) => {
- const qty = parseInt($(e.target).val()) || 0;
- const itemCheckbox = $(e.target).parent().parent().parent().find(".sdb-item-checkbox")[0];
- if (!$(itemCheckbox).is(":checked") && qty > 0) {
- $(itemCheckbox).click();
- }
- });
- $(".np-stepper-btn").on("click", (e) => {
- $(e.target).parent().find(".np-stepper-input")[0].dispatchEvent(new Event("keyup"));
- });
- const row = $(".sdb-row-odd")[0];
- $(row).attr("init", true);
- };
- $(document).keypress((e) => {
- const key = e.which;
- if (key == 13) { // when pressing enter
- if ($(".sdb-confirm-body input[type=password]").length) { // if the PIN prompt is active
- const button = $("#sdb__popup > .popup-footer__2020 > div > .np-button")[1];
- if (button && $(button).text() === "Confirm") {
- $(button).click();
- }
- }
- else if ($(".sdb-drawer").length) { // if the bulk action footer is active
- const dropdown = $(".sdb-drawer > .sdb-drawer-content > .sdb-drawer-action-row > .sdb-as > .sdb-action-select")[0];
- if ($(dropdown).val()) { // user has selected an action
- const button = $(".sdb-drawer > .sdb-drawer-content > .sdb-drawer-buttons > .np-button")[1];
- if (button && $(button).text() === "Confirm") {
- $(button).click();
- }
- }
- }
- }
- });
- const interval = setInterval(() => {
- // 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
- // so this is just a failsafe for initial app load
- if ($(".np-stepper-input").length) {
- console.log("Interval setup");
- if (!checkInit()) {
- setupBehaviour();
- }
- clearInterval(interval);
- }
- }, 200);
- const observer = new MutationObserver(() => {
- console.log("Observer triggered");
- if (!checkInit()) {
- setupBehaviour();
- }
- });
- observer.observe(document.querySelector("#sdb-vue-app"), {childList: true, subtree: true});
- })();
Advertisement
Add Comment
Please, Sign In to add comment