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