Greasy Fork is available in English.

Neopets: Inventory Rarity Display

Displays rarity on inventory items

  1. // ==UserScript==
  2. // @name Neopets: Inventory Rarity Display
  3. // @namespace Nyu@Clraik
  4. // @version 1.0.1
  5. // @description Displays rarity on inventory items
  6. // @author Nyu
  7. // @match *://*.neopets.com/inventory.phtml
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=neopets.com
  9. // ==/UserScript==
  10.  
  11.  
  12. (async () => {
  13. await addRarities()
  14.  
  15. const toggleButton = document.querySelector('.nptoggle')
  16. toggleButton.addEventListener('click', async () => {
  17. await addRarities()
  18. })
  19.  
  20. async function addRarities(){
  21. await waitForInventoryLoaded()
  22. const items = Array.from(document.querySelectorAll(`[class*="item-img"]`))
  23.  
  24. for (const item of items) {
  25. const rarity = item.dataset.rarity
  26. const div = document.createElement('div')
  27. div.style.position = 'absolute'
  28. div.style.top = '0px'
  29. div.style.width = 'fit-content'
  30. div.style.color = 'white'
  31. div.style.fontFamily = 'MuseoSansRounded500'
  32. div.style.backgroundColor = getBackgroundColor(rarity)
  33. div.classList = 'inv-menulinks'
  34. div.innerText = 'r'+rarity
  35. item.append(div)
  36.  
  37. }
  38. }
  39.  
  40. async function waitForInventoryLoaded() {
  41. await sleep(100)
  42. while (document.querySelector('.inv-loading-static')) {
  43. await sleep(1000)
  44. }
  45. }
  46.  
  47. function getBackgroundColor(rarity) {
  48. return rarity == 99 ? 'green' : rarity == 500 ? 'gold' : rarity == 180 ? '#666666' : rarity < 75 ? '#dda713' : rarity >= 75 && rarity < 101 ? '#7ba515' : rarity >= 101 && rarity <= 104 ? '#aa4455' : rarity <= 105 && rarity < 111 ? 'orange' : rarity >= 111 ? 'red' : '#000'
  49. }
  50.  
  51. function sleep(ms) {
  52. return new Promise(resolve => setTimeout(resolve, ms));
  53. }
  54. })();