🐭️ MouseHunt - Item Quantity Fix

Fixes the "You Own: 0" bug when viewing an item info page.

  1. // ==UserScript==
  2. // @name 🐭️ MouseHunt - Item Quantity Fix
  3. // @version 1.1.0
  4. // @description Fixes the "You Own: 0" bug when viewing an item info page.
  5. // @license MIT
  6. // @author bradp
  7. // @namespace bradp
  8. // @match https://www.mousehuntgame.com/i.php
  9. // @icon https://brrad.com/mouse.png
  10. // @grant none
  11. // @run-at document-end
  12. // ==/UserScript==
  13.  
  14. ((function () {
  15. 'use strict';
  16.  
  17. // Make sure we have the ID parameter.
  18. if (window.location.href.indexOf('i.php?id=') === -1) {
  19. return;
  20. }
  21.  
  22. // Grab the item ID.
  23. const itemID = window.location.href.split('i.php?id=')[ 1 ];
  24. if (! itemID) {
  25. return;
  26. }
  27.  
  28. // Make sure the quantity shown is 0.
  29. const qty = document.querySelector('.itemView-sidebar-quantity');
  30. if (! (qty && qty.textContent.indexOf('You Own:') !== -1)) {
  31. return;
  32. }
  33.  
  34. // Grab the item slug.
  35. const itemName = document.querySelector('.itemViewContainer').getAttribute('data-item-type');
  36. if (! itemName) {
  37. return;
  38. }
  39.  
  40. // redirect to item.php?item_type=itemName
  41. const newLocation = window.location.href.replaceAll(`i.php?id=${itemID}`, `item.php?item_type=${itemName}`);
  42. if (newLocation !== window.location.href) {
  43. window.location.href = newLocation;
  44. }
  45. })());