forked from Chromatically/Chro-MH
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMH - Map Crown Display.js
144 lines (129 loc) · 5.13 KB
/
MH - Map Crown Display.js
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
// ==UserScript==
// @name MH - Map Crown Display
// @version 2.0.1
// @description Adds catch/crown statistics next to mouse names on the map
// @author Chromatical
// @match https://www.mousehuntgame.com/camp.php
// @icon https://www.google.com/s2/favicons?domain=mousehuntgame.com
// @namespace https://greasyfork.org/users/748165
// ==/UserScript==
$(document).ajaxComplete(function(event,xhr,options){
if (options.url == "https://www.mousehuntgame.com/managers/ajax/board/board.php"){
$(".treasureMapView-mapMenu-rewardName")[0].innerText.includes("Scavenger")? null : replace()
};
localStorage.getItem('Chro-map-tem') !== null? updateTime(): createTime()
async function updateTime(){
var date = Date.now()
var lastTime = localStorage.getItem('Chro-map-tem')
var d = new Date(lastTime).getTime()
if (date - d > 43200000){
const promise = await getCrowns().
then(res=>{
localStorage.setItem('Chro-map-tem',date);
localStorage.setItem('Chro-map-tem-mice',JSON.stringify(res));
})
}
}
async function createTime(){
var date = Date.now();
const promise2 = getCrowns().
then(res=>{
localStorage.setItem('Chro-map-tem',date);
localStorage.setItem('Chro-map-tem-mice',JSON.stringify(res));
})
}
})
document.onclick = function(){
if ($(".treasureMapRootView")[0]){
typeof $(".mousebox2")[0] == "object"? null: replace()
}
}
async function replace(){
if ($(".mousebox2")[0]){return} else {
document.querySelectorAll(".treasureMapView-goals-group-goal").forEach(el => {
var span = el.querySelector("span")
span.style = "width: auto; height: auto; font-size: 10px;";
const outer = document.createElement("span");
outer.className = "mousebox2";
outer.style.fontColor = "black";
outer.style.width = "auto";
outer.style.height = "auto";
outer.style.margin = "0px";
outer.style.paddingRight = "8px";
outer.style.paddingLeft = "3px";
outer.style.float = "none";
const crownImg = document.createElement("img");
crownImg.style.width = "18px";
crownImg.style.height = "18px";
crownImg.style.paddingTop = "2px";
crownImg.style.paddingBottom = "1px";
crownImg.style.right = "-4px";
crownImg.style.position = "relative";
crownImg.style.float = "right";
var mouseName = el.textContent
var miceList = JSON.parse(localStorage.getItem('Chro-map-tem-mice'));
var catches = miceList[mouseName];
function getCrownSrc(type) {
return `https://www.mousehuntgame.com/images/ui/crowns/crown_${type}.png`;
}
if (!catches || catches < 10) {
crownImg.src = getCrownSrc("none");
} else if (catches >= 10 && catches < 100) {
crownImg.src = getCrownSrc("bronze");
} else if (catches >= 100 && catches < 500) {
crownImg.src = getCrownSrc("silver");
} else if (catches >= 500 && catches < 1000) {
crownImg.src = getCrownSrc("gold")
} else if (catches >= 1000 && catches < 2500) {
crownImg.src = getCrownSrc("platinum");
} else if (catches >= 2500) {
crownImg.src = getCrownSrc("diamond");
}
const text = document.createElement("div");
text.innerText = catches || 0
text.style = "text-align: center"
text.style.float = "left";
text.style.color = "black";
text.style.paddingTop = "5px";
outer.appendChild(text);
outer.appendChild(crownImg)
span.appendChild(outer);
})
}
function getCrowns(){
return new Promise((resolve, reject) => {
postReq("https://www.mousehuntgame.com/managers/ajax/mice/getstat.php",`sn=Hitgrab&hg_is_ajax=1&action=get_hunting_stats&uh=${user.unique_hash}`)
.then(
res=>{
try{
var data = JSON.parse(res.responseText);
if(data){
var miceList={};
data.hunting_stats.forEach(mouse=>{
var mouseName = mouse.name.replace(/\ mouse$/i, "")
miceList[mouseName] = mouse.num_catches
})
}
resolve(miceList)
} catch(err) {
console.log(err)
}
})
})
}
function postReq(url, form) {
return new Promise((resolve, reject) => {
const xhr = new XMLHttpRequest();
xhr.open("POST", url, true);
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.onreadystatechange = function () {
if (this.readyState === XMLHttpRequest.DONE && this.status === 200) {
resolve(this);
}
};
xhr.onerror = function () {
reject(this);
};
xhr.send(form);
});}
}