// ==UserScript== // @name MH: Inventory History // @author Warden Slayer - Warden Slayer#2302 // @namespace https://greasyfork.org/en/users/227259-wardenslayer // @version 0.91 // @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 // // @downloadURL none // ==/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() { fetchInventory(); getMice(); publishResults(); } 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],['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_link_turns','num_total_turns','map_num_clues_found','map_num_maps_dusted','wisdom'],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]; const wisdom = ['Wisdom',data[0].wisdom]; 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,wisdom); getCrowns(itemsArray); }) return itemsArray } function getCrowns (itemsArray) { hg.utils.MouseUtil.getCrowns(function(data) { data.forEach(function(arrayItem, i) { let crownName = arrayItem.name; if (arrayItem.type == "none") { crownName = 'Uncrowned Mice'; } else { crownName = crownName.concat(' Crowns'); } itemsArray.push([crownName,arrayItem.count]); }) localStorage.setItem('ws.mh.invHx', JSON.stringify(itemsArray)) }) return itemsArray } function getMice() { let mouseArray = []; hg.utils.MouseUtil.getHuntingStats(function(data) { data.forEach(function(arrayItem, index) { const mouseName = correctMouseName(arrayItem.name); mouseArray[index] = [mouseName, arrayItem.num_catches, arrayItem.num_misses]; }) localStorage.setItem('ws.mh.invHx.mice', JSON.stringify(mouseArray)); }) return mouseArray } function correctMouseName(mouseName) { mouseName = mouseName.replace(" Mouse", ""); let newMouseName = ""; if (mouseName == "Ful'Mina, The Mountain Queen") { newMouseName = "Ful'mina the Mountain Queen"; } else if (mouseName == "Inferna, The Engulfed") { newMouseName = "Inferna the Engulfed"; } else if (mouseName == "Nachous, The Molten") { newMouseName = "Nachous the Molten"; } else if (mouseName == "Stormsurge, the Vile Tempest") { newMouseName = "Stormsurge the Vile Tempest"; } else if (mouseName == "Bruticus, the Blazing") { newMouseName = "Bruticus the Blazing"; } else if (mouseName == "Vincent, The Magnificent") { newMouseName = "Vincent The Magnificent"; } else if (mouseName == "Corky, the Collector") { newMouseName = "Corky the Collector"; } else { newMouseName = mouseName; } return newMouseName; } function publishResults(){ const debug = localStorage.getItem('ws.debug'); const webAppURL = localStorage.getItem('ws.mh.invHx.webApp'); let timestamp_label = localStorage.getItem('ws.mh.invHx.dataLabel'); const itemArray = localStorage.getItem('ws.mh.invHx'); const mouseArray = localStorage.getItem('ws.mh.invHx.mice'); if (debug == true) { console.log('Inventory',itemArray) console.log('Mice',mouseArray) } if (timestamp_label) { } else { 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: itemArray, timestamp: timestamp_label,mice: mouseArray}), onload: function(response) { if (debug == true) { console.log('Inventory Submitted') } localStorage.setItem('ws.mh.invHx.dataLabel',"") }, 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: '' + '
' + '
' + '' + '' + '
' + '' + '' + '
' + '', 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(); const dataLabel = this.$content.find('.inventory.nickname').val(); if (link) { localStorage.setItem('ws.mh.invHx.dataLabel',dataLabel) localStorage.setItem('ws.mh.invHx.webApp',link) getInvNow(); } else if (localStorage.getItem('ws.mh.invHx.webApp')) { localStorage.setItem('ws.mh.invHx.dataLabel',dataLabel) 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() { } }, } }) }