Neopets Lab Rat Filter

Hide all pets except your specified lab rats so you don't accidentally zap them!

  1. // ==UserScript==
  2. // @name Neopets Lab Rat Filter
  3. // @version 0.1
  4. // @description Hide all pets except your specified lab rats so you don't accidentally zap them!
  5. // @author darknstormy
  6. // @match http*://www.neopets.com/lab2.phtml
  7. // @icon https://www.google.com/s2/favicons?domain=neopetsclassic.com
  8. // @license MIT
  9. // @grant none
  10. // @namespace https://greasyfork.org/en/users/798613
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. 'use strict';
  15.  
  16. const LAB_RATS = ["Buzzolt"]
  17.  
  18. waitForElement('form[action="process_lab2.phtml"]').then(form => {
  19. form.find("input").filter(
  20. function() {
  21. // Do not hide the submit button or any lab rats
  22. return $(this).attr('type') !== "submit" && $.inArray($(this).val(), LAB_RATS) === -1
  23. }).parent().hide()
  24. });
  25. })();
  26.  
  27.  
  28. function waitForElement(selector) {
  29. return new Promise(resolve => {
  30. if ($(selector).is(":visible")) {
  31. return resolve($(selector));
  32. }
  33.  
  34. const observer = new MutationObserver(mutations => {
  35. if ($(selector).is(":visible")) {
  36. observer.disconnect();
  37. resolve($(selector));
  38. }
  39. })
  40.  
  41. // If you get "parameter 1 is not of type 'Node'" error, see https://stackoverflow.com/a/77855838/492336
  42. observer.observe(document.body, {
  43. childList: true,
  44. subtree: true
  45. })
  46. })
  47. }