Greasy Fork is available in English.
See and change charms on your bwrift HUD!
当前为
// ==UserScript==
// @name MH - BWrift HUD Enhancer(Charms)
// @version 1.0.1
// @description See and change charms on your bwrift HUD!
// @author Chromatical
// @match https://www.mousehuntgame.com/*
// @match https://apps.facebook.com/mousehunt/*
// @icon https://www.google.com/s2/favicons?domain=mousehuntgame.com
// @grant none
// @namespace http://greasyfork.icu/users/748165
// ==/UserScript==
(function() {
if (user.environment_name == "Bristle Woods Rift"){
huntListener();
getData();
}
})();
var vac_quantity = 0;
var super_vac_quantity = 0;
var anti_skele_quantity = 0;
function huntListener(){
const originalOpen = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function (){
this.addEventListener("load",function(){
if (this.responseURL === "https://www.mousehuntgame.com/managers/ajax/turns/activeturn.php" ||this.responseURL === "https://www.mousehuntgame.com/managers/ajax/pages/page.php"){
success:{update()}
}
})
originalOpen.apply(this,arguments);
};
};
function getData(){
postReq("https://www.mousehuntgame.com/managers/ajax/users/gettrapcomponents.php",
`sn=Hitgrab&hg_is_ajax=1&uh=${user.unique_hash}&classification=trinket`
).then(res=>{
try {
var response = JSON.parse(res.responseText);
if (response) {
for (var i = 0;i<response.components.length;i++){
if (response.components[i].name == "Rift Vacuum Charm"){
vac_quantity = response.components[i].quantity;
} else if (response.components[i].name == "Rift Super Vacuum Charm"){
super_vac_quantity = response.components[i].quantity;
} else if (response.components[i].name == "Rift Antiskele Charm"){
anti_skele_quantity = response.components[i].quantity;
}
}
render();
}
} catch (error) {
console.error(error.stack);
}
});
}
function render(){
var charm_container = document.createElement("div");
charm_container.title = "Click to charm charms"
charm_container.className = "charm_container";
charm_container.style.position = "absolute";
charm_container.style.left = "247px";
charm_container.style.top = "153px";
charm_container.style.width = "100px";
var vac_charm_btn = document.createElement("button");
vac_charm_btn.style.filter = "brightness(0.5)"
vac_charm_btn.className = "Charm-Btn"
vac_charm_btn.style.backgroundImage = "url('https://www.mousehuntgame.com/images/items/trinkets/08c2297af0dac1e26490ce3f814df026.gif')"
vac_charm_btn.style.backgroundSize = "30px"
vac_charm_btn.style.position = "relative"
vac_charm_btn.style.width = "33px"
vac_charm_btn.style.height = "33px"
vac_charm_btn.style.borderRadius = "5px"
vac_charm_btn.style.textAlign = "center"
vac_charm_btn.style.borderColor = "#4db6ff"
var vac_count = document.createElement("div");
vac_count.className = "Charm-Quantity"
vac_count.style.fontSize = "9px"
vac_count.style.position = "absolute"
vac_count.style.backgroundColor = "white"
vac_count.style.minWidth = "15px"
vac_count.style.top = "19px"
vac_count.style.right = "1px"
vac_count.style.color = "black";
vac_count.style.borderStyle = "solid"
vac_count.style.borderWidth = "thin"
vac_count.style.borderColor = "grey"
vac_count.style.borderRadius = "5px"
var vac_id = document.createElement("div")
vac_id.className = "charm-id"
vac_id.innerText = 1553
vac_id.style.display = "none"
var super_vac_charm_btn = vac_charm_btn.cloneNode(true);
super_vac_charm_btn.style.backgroundImage = "url('https://www.mousehuntgame.com/images/items/trinkets/a8857b31040f508bf0c1b9f506afc95a.gif')"
var anti_skele_btn = vac_charm_btn.cloneNode(true);
anti_skele_btn.style.backgroundImage = "url('https://www.mousehuntgame.com/images/items/trinkets/7218005f9062e881a6a2991ba58db829.gif')"
var super_vac_count = vac_count.cloneNode(true);
var anti_skele_count = vac_count.cloneNode(true);
vac_count.textContent = vac_quantity;
super_vac_count.textContent = super_vac_quantity;
anti_skele_count.textContent = anti_skele_quantity;
var super_vac_id = vac_id.cloneNode(true);
super_vac_id.innerText = 1841
var anti_skele_id = vac_id.cloneNode(true);
anti_skele_id.innerText = 2322
vac_charm_btn.appendChild(vac_count);
vac_charm_btn.appendChild(vac_id);
super_vac_charm_btn.appendChild(super_vac_count);
super_vac_charm_btn.appendChild(super_vac_id);
anti_skele_btn.appendChild(anti_skele_count);
anti_skele_btn.appendChild(anti_skele_id);
charm_container.appendChild(vac_charm_btn);
charm_container.appendChild(super_vac_charm_btn);
charm_container.appendChild(anti_skele_btn);
var ori_box = $(".riftBristleWoodsHUD-itemContainer")[0];
ori_box.insertAdjacentElement("afterend",charm_container);
active();
}
function active(){
var btns = document.getElementsByClassName("Charm-Btn");
const charm = [1553,1841,2322];
var currentCharm = user.trinket_item_id;
// Loop through the buttons and add the active class to the current/clicked button
for (var i = 0; i < btns.length; i++) {
//Initial colour
if (currentCharm == charm[i]){
btns[i].className += " active";
btns[i].style.borderColor = "#33ff1e"
btns[i].style.filter = "brightness(1.0)"
}
btns[i].addEventListener("click", function() {
var current = document.getElementsByClassName("Charm-Btn active");
if(current[0] == this){
//Disarm
hg.utils.TrapControl.disarmTrinket().go()
current[0].style.borderColor = "#4db6ff"
current[0].style.filter = "brightness(0.5)"
current[0].className = current[0].className.replace(" active", "");
} else if (current.length == 0){
//Changing to one of the charms
hg.utils.TrapControl.setTrinket(this.firstElementChild.nextElementSibling.innerText).go();
this.className += " active";
this.style.borderColor = "#33ff1e"
this.style.filter = "brightness(1.0)"
} else {
//Changing from one to another
current[0].style.borderColor = "#4db6ff"
current[0].style.filter = "brightness(0.5)"
current[0].className = current[0].className.replace(" active", "");
hg.utils.TrapControl.setTrinket(this.firstElementChild.nextElementSibling.innerText).go();
this.className += " active";
this.style.borderColor = "#33ff1e"
this.style.filter = "brightness(1.0)"
}
});
}
}
function update(){
postReq("https://www.mousehuntgame.com/managers/ajax/users/gettrapcomponents.php",
`sn=Hitgrab&hg_is_ajax=1&uh=${user.unique_hash}&classification=trinket`
).then(res=>{
try {
var response = JSON.parse(res.responseText);
if (response) {
document.getElementsByClassName("Charm-Quantity")[0].textContent = 0;
document.getElementsByClassName("Charm-Quantity")[1].textContent = 0;
document.getElementsByClassName("Charm-Quantity")[2].textContent = 0;
for (var i = 0;i<response.components.length;i++){
if (response.components[i].name == "Rift Vacuum Charm" && response.components[i].quantity){
document.getElementsByClassName("Charm-Quantity")[0].textContent = response.components[i].quantity;
} else if (response.components[i].name == "Rift Super Vacuum Charm" && response.components[i].quantity){
document.getElementsByClassName("Charm-Quantity")[1].textContent = response.components[i].quantity;
} else if (response.components[i].name == "Rift Antiskele Charm" && response.components[i].quantity){
document.getElementsByClassName("Charm-Quantity")[2].textContent = response.components[i].quantity;
}
}
}
} catch (error) {
console.error(error.stack);
}
});
}
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);
});
}