// ==UserScript==
// @name MH: Inventory History
// @author Warden Slayer - Warden Slayer#2302
// @namespace https://greasyfork.org/en/users/227259-wardenslayer
// @version 0.8
// @description Coming Soon
// @resource YOUR_CSS https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.css
// @require https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.11.2/js/all.js
// @require https://cdnjs.cloudflare.com/ajax/libs/jquery-confirm/3.3.2/jquery-confirm.min.js
// @include https://ajax.googleapis.com/ajax/libs/jquery/1.6.2/jquery.min.js
// @include http://www.mousehuntgame.com/*
// @include https://www.mousehuntgame.com/*
// @grant GM_setClipboard
// @grant GM_xmlhttpRequest
// @grant GM_getResourceText
// @connect self
// @connect script.google.com
// @connect script.googleusercontent.com
//
// ==/UserScript==
$(document).ready(function() {
addTouchPoint()
});
function addTouchPoint() {
if ($('.invHix').length == 0) {
const invPages = $('.inventory .torn_pages');
//Inventory History Button
const invHix = document.createElement('li');
invHix.classList.add('invHix');
const invHixBtn = document.createElement('a');
invHixBtn.href = "#";
invHixBtn.innerText = "Inventory History";
invHixBtn.onclick = function () {
onInvHXOnClick();
};
const icon = document.createElement("div");
icon.className = "icon";
invHixBtn.appendChild(icon);
invHix.appendChild(invHixBtn);
$(invHix).insertAfter(invPages);
}
}
function getInvNow() {
const debug = localStorage.getItem('ws.debug');
fetchInventory();
if (debug == true) {
console.log('Inventory',localStorage.getItem('ws.mh.invHx'))
}
publishResults(localStorage.getItem('ws.mh.invHx'));
}
function fetchInventory() {
const itemsToGet = ['weapon','base', 'trinket', 'bait', 'skin', 'crafting_item','convertible', 'potion', 'stat','collectible']; //future proof this to allow for exclusions
let itemsArray = [];
let finalCSV = "";
hg.utils.UserInventory.getItemsByClass(itemsToGet,true,function(data) {
data.forEach(function(arrayItem, index) {
itemsArray[index] = [arrayItem.name,arrayItem.quantity];
})
//hunter stats
itemsArray.push(['Rank Percent',user.title_percent_accurate],['Wisdom',user.title_wisdom],['Points',user.points],['Gold',user.gold]);
getHunts(itemsArray);
})
return itemsArray
}
function getHunts(itemsArray) {
let hunts = [];
hg.utils.User.getUserData([user.sn_user_id],['num_active_turns','num_passive_turns','num_linked_turns','num_total_turns','map_num_clues_found','map_num_maps_dusted'],function(data) {
const numClues = ['Map Clues',data[0].map_num_clues_found];
const numDust = ['Maps Dusted',data[0].map_num_maps_dusted];
const numHorns = ['Horn Calls',data[0].num_active_turns];
const numTrapChecks = ['Trap Checks',data[0].num_passive_turns];
let numFriendHorns = [];
if(data[0].num_link_turns) {
numFriendHorns = ['Friend Horn',data[0].num_link_turns];
} else {
numFriendHorns = ['Friend Horn',data[0].num_total_turns-data[0].num_active_turns-data[0].num_passive_turns];
}
const numHunts = ['Total Hunts',data[0].num_total_turns];
itemsArray.push(numHorns,numTrapChecks,numFriendHorns,numHunts,numClues,numDust)
localStorage.setItem('ws.mh.invHx', JSON.stringify(itemsArray));
})
return itemsArray
}
function publishResults(results){
const debug = localStorage.getItem('ws.debug');
const webAppURL = localStorage.getItem('ws.mh.invHx.webApp');
let timestamp_label = "";
//dummy label for now
timestamp_label = new Date().toString().split(" G")[0];
if (webAppURL){
if (debug == true) {
console.log(webAppURL)
}
GM_xmlhttpRequest({
method: "POST",
url: webAppURL,
data: JSON.stringify({ inventory: results, timestamp: timestamp_label}),
onload: function(response) {
if (debug == true) {
console.log('Inventory Submitted')
}
},
onerror: function(response) {
if (debug == true) {
console.log('No Good, Error')
}
}
});
} else {
myAlert();
}
}
//========== Modals ======================//
//https://craftpip.github.io/jquery-confirm/#getting-started
function onInvHXOnClick(){
$.confirm({
title: 'MH: Inventory History',
content: 'Provide your web app link here. Only needed the first time unless you need to update it.' +
'<form action="" class="formName">' +
'<div class="form-group">' +
'<input type="text" placeholder="Paste Web App Link Here" class="webapp link" size="100" "/>' +
'</div>' +
'</form>',
boxWidth: '50%',
useBootstrap: false,
closeIcon: true,
icon: 'fas fa-history',
draggable: true,
theme: 'dark',
buttons: {
formSubmit: {
text: 'Submit Inventory',
btnClass: 'btn-blue',
action: function () {
const link = this.$content.find('.webapp.link').val();
if (link) {
localStorage.setItem('ws.mh.invHx.webApp',link)
getInvNow();
} else if (localStorage.getItem('ws.mh.invHx.webApp')) {
getInvNow();
} else {
myAlert();
}
}
},
cancel: function () {
},
},
})
}
function myAlert() {
var icon = 'fas fa-exclamation-circle'
var title = "WebApp Link Error"
$.alert({
autoClose: 'acknowledge|60000',
title: title,
content: 'There was an issue with your web app link. Please paste it in again',
icon: icon,
type: 'dark',
typeAnimated: true,
boxWidth: '30%',
useBootstrap: false,
draggable: true,
escapeKey: 'aknowledge',
buttons: {
acknowledge: {
text: 'Ok',
keys: ['enter', 'space'],
btnClass: 'btn-red',
action: function() {
}
},
}
})
}