// ==UserScript== // @name MH: Profile+ // @author Warden Slayer - Warden Slayer#2010 // @namespace https://greasyfork.org/en/users/227259-wardenslayer // @version 1.19 // @description Community requested features for the tabs on your MH profile. // @grant GM_xmlhttpRequest // @include https://ajax.googleapis.com/ajax/libs/jquery/3.6.0/jquery.min.js // @include http://www.mousehuntgame.com/* // @include https://www.mousehuntgame.com/* // @connect http://www.mousehuntgame.com/* // @connect https://www.mousehuntgame.com/* // @grant GM_setClipboard // @downloadURL none // ==/UserScript== $(document).ready(function() { const debug = localStorage.getItem('ws.debug'); if (debug == true) { console.log('Profile+ Started'); }; localStorage.setItem('ws.pfp.sortUorD','down'); loadFunction(); }); function loadFunction(){ if ($('.mousehuntHud-page-tabHeader.kings_crowns').hasClass('active')) { //On king's crowns tab generateCrowns(); } else if ($('.mousehuntHud-page-tabHeader.items').hasClass('active')) { //On item tab manageCollected(); } else if ($('.mousehuntHud-page-tabHeader.profile').hasClass('active')) { //On profile tab generateProfile(); } else if ($('.mousehuntHud-page-tabHeader.mice').hasClass('active')) { //On mouse Tab generateMice(); } else { return false } } $(document).ajaxComplete(function(event,xhr,options){ if (options.url == 'https://www.mousehuntgame.com/managers/ajax/users/userData.php') { } else { loadFunction(); } }); ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Profile TAB // // // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function generateProfile() { //With the mhcc level, an egg, a checkmark, a crown, a star const debug = localStorage.getItem('ws.debug'); let userID = ""; const myProfileLink = $('.mousehuntHud-shield').attr('href'); let maybeYourFriend = ""; let eggMaster = localStorage.getItem('ws.pfp.eggMaster'); if ($('.userInteractionButtonsView-relationship').get(0)) { userID = $('.userInteractionButtonsView-relationship').attr('data-recipient-snuid'); maybeYourFriend = userID; } else if (myProfileLink) { if (myProfileLink.search('snuid=')==-1) { if (debug == true) { console.log('Your SNUID Not Found',myProfileLink); }; return false; } else { userID = myProfileLink.split('snuid=')[1].split('&tab=')[0]; } } else { if (debug == true) { console.log('SNUID Not Found',myProfileLink,userID); }; return false; } const snuidOld = localStorage.getItem('ws.pfp.snuid'); localStorage.setItem('ws.pfp.snuid',userID); if (snuidOld == userID) { if (eggMaster == 'true') { flexEggMaster(); } } else { localStorage.setItem('ws.pfp.eggMaster',"") const dataItemOfInterest = ['is_egg_master','not_a_real_field']; hg.utils.User.getUserData([userID],dataItemOfInterest,function(data) { eggMaster = localStorage.setItem('ws.pfp.eggMaster',data[0].is_egg_master); }); setTimeout(flexEggMaster, 1000); } if (debug == true) { console.log('Profile Tab',snuidOld,userID,eggMaster); }; //stop the silly hyperlink on the hunter ID const hunterID = $('.hunterInfoView-idCardBlock-secondaryHeader').children(); hunterID.removeAttr("href").removeAttr("onclick"); // //tipping/misc if (maybeYourFriend) { const yourFriendsProfile = $('.friendsPage-friendRow-content'); if ($('#tipButton').get(0)) { return false; } else { $('.friendsPage-friendRow-content').css({ 'padding-top': '0px', }); const tipButton = document.createElement("button"); tipButton.id = "tipButton"; $(tipButton).attr('title', 'Tip this hunter 10 SB+'); $(tipButton).text('Tip 10 SB+'); yourFriendsProfile.prepend(tipButton); $(tipButton).css({ 'background-image': "url('https://www.toptal.com/designers/subtlepatterns/patterns/interlaced.png')", 'background-repeat': 'no-repeat', 'background-size': 'contain', 'position': 'relative', 'left': '37px', 'width': '85px', 'height': '20px', }); } } else if ($('.friendsProfileView-selfStats').get(0)) { const randomFriend = $('.friendsProfileView-randomFriend'); const randoSNUID = randomFriend.attr('href').split('snuid=')[1].split('&tab=')[0]; hg.utils.User.getUserData([randoSNUID],['not_a_real_field'],function(data) { randomFriend.text('Visit Random Friend ('+data[0].name+')'); }); } } function flexEggMaster() { const eggMaster = localStorage.getItem('ws.pfp.eggMaster'); if (eggMaster == 'true') { if ($(".eggMasterIcon").length > 0) return; const hunterID = $('.friendsPage-friendRow-titleBar'); const eggMasterIcon = document.createElement("div"); eggMasterIcon.classList.add("eggMasterIcon"); $(eggMasterIcon).attr('title', 'Is an Egg Master') $(eggMasterIcon).css({ 'background-size': '25px 25px', 'background-image': "url('https://i.ibb.co/qj01CGk/image-removebg-preview-35.png')", 'width': '25px', 'height': '25px', 'float': 'right', 'margin-right': '7px', }); hunterID.append(eggMasterIcon) } } $(document).on('click', '#tipButton', function() { const debug = localStorage.getItem('ws.debug'); const receivingHunter = $('.userInteractionButtonsView-relationship').attr('data-recipient-snuid'); const receivingName = $('.friendsPage-friendRow-titleBar-name').attr('data-text'); const sendingHunter = user.unique_hash; const url = 'https://www.mousehuntgame.com/managers/ajax/users/supplytransfer.php?/sn=Hitgrab&hg_is_ajax=1&receiver='+receivingHunter+'&uh='+sendingHunter+'&item=super_brie_cheese&item_quantity=10'; GM_xmlhttpRequest({ method: "POST", url: url, onload: function(response) { if (debug == true) { console.log('Tip Sent',receivingName,receivingHunter); } alert('10 SB+ sent to '+receivingName); }, onerror: function(response) { if (debug == true) { console.log('Tip No Good, Error',receivingName,receivingHunter,url); } alert('Error, nothing sent'); } }); }) $(document).on('click', '.hunterInfoView-idCardBlock-secondaryHeader', function() { const debug = localStorage.getItem('ws.debug'); const copiedID = $('.hunterInfoView-hunterId').find('span').text(); if (debug == true) { console.log('ID Copied',copiedID) }; GM_setClipboard(copiedID); }) ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Mouse TAB // // // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function generateMice() { const debug = localStorage.getItem('ws.debug'); const allMice = $('.mouseListView-categoryContent-subgroup-mouse.stats:not(.header)'); const statsHeader = $('.mouseListView-categoryContent-subgroup-mouse.stats.header'); allMice.each(function(i) { const thisThumb = $(this).find('.mouseListView-categoryContent-subgroup-mouse-thumb'); const thisCatches = parseInt($(this).find('.catches').text().replace(",", ""),10); const thisMisses = parseInt($(this).find('.misses').text().replace(",", ""),10); setCrownBorder(thisThumb,thisCatches); }); $(statsHeader).css({ 'cursor': 'pointer', }); } // $(document).on('click', '.mouseListView-categoryContent-subgroup-mouse-stats', function() { // const sortUorD = localStorage.getItem('ws.pfp.sortUorD'); // let sortKey = ""; // if ($(this).hasClass('name')) { // sortKey = '.name'; // } else if ($(this).hasClass('catches')) { // sortKey = '.catches'; // } else if ($(this).hasClass('misses')) { // sortKey = '.misses'; // } else if ($(this).hasClass('average_weight')) { // sortKey = '.average_weight'; // } else if ($(this).hasClass('heaviest_catch')) { // sortKey = '.heaviest_catch'; // } // if (sortUorD == 'up') { // sortMiceBy(sortKey,'down'); // localStorage.setItem('ws.pfp.sortUorD','down'); // } else { // sortMiceBy(sortKey,'up'); // localStorage.setItem('ws.pfp.sortUorD','up'); // } // }); function setCrownBorder(thumb,catches) { let top = ""; let bottom = ""; if ((catches >= 10) && (catches < 100)) { top = '#f0c693'; bottom = '#8d4823'; } else if ((catches >= 100) && (catches < 500)) { top = '#d1d7e9'; bottom = '#66718b'; } else if ((catches >= 500) && (catches < 1000)) { top = '#ffe589'; bottom = '#b67800'; } else if ((catches >= 1000) && (catches < 2500)) { top = '#9191ff'; bottom = '#1d1781'; } else if (catches >= 2500) { top = '#c4eae6'; bottom = '#63b9cf'; } else { //no crown top = '#ab9f92'; bottom = '#251B0A'; } $(thumb).css({ 'border-style': 'solid', 'border-width': '4px', 'border-radius': '4px', 'border-top-color': top, 'border-left-color': top, 'border-bottom-color': bottom, 'border-right-color': bottom, }); } function sortMiceBy(key,UD) { const mouseContainer = $('.mouseListView-categoryContent-subgroupContainer'); const allMice = $('.mouseListView-categoryContent-subgroup-mouse.stats:not(.header)'); $(allMice).sort(function(a, b,) { if (key == '.name') { a = $(a).find(key).text(); b = $(b).find(key).text(); if ((UD == 'up') && (a < b)) { return -1; } else if ((UD == 'up') && (a > b)) { return 1; } else if ((UD == 'down') && (a > b)) { return -1; } else if ((UD == 'down') && (a < b)) { return 1; } } else if ((key == '.catches') || (key == '.misses')) { a = parseInt($(a).find(key).text(),10); b = parseInt($(b).find(key).text(),10); if ((UD == 'up') && (a > b)) { return -1; } else if ((UD == 'up') && (a < b)) { return 1; } else if ((UD == 'down') && (a < b)) { return -1; } else if ((UD == 'down') && (a > b)) { return 1; } } else if ((key == '.average_weight') || (key == '.heaviest_catch')) { // do nothing for now cause parsing lbs/oz is no fun } }).appendTo(mouseContainer); } ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Crowns TAB // // // ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// function generateCrowns() { const debug = localStorage.getItem('ws.debug'); if (debug == true) { console.log('Crowns Tab',localStorage.getItem("Lock Favorites"),localStorage.getItem("ShowCommunityRanks")); }; buildToolbar(); decorate(); if (localStorage.getItem("Lock Favorites") == "Y" && $(".mouseCrownsView-group-mouse-favouriteButton").length > 0) { lockFavorites(); } if (localStorage.getItem("ShowCommunityRanks") == "Y") { localStorage.setItem('ws.mh.pfp.numMice',""); hg.utils.MouseUtil.getMouseNames(function (data) { const numMice = Object.keys($(data)[0]).length-2; localStorage.setItem('ws.mh.pfp.numMice',numMice); if (debug == true) { console.log('Total Mice',numMice); }; }) setTimeout(showCommunityRanks, 1000) } } function buildToolbar() { if ($(".toolBar").length > 0) return; const toolBar = document.createElement("div"); toolBar.classList.add("toolBar"); // Lock Favs CB const lockFavs = document.createElement("input"); lockFavs.type = "checkbox"; lockFavs.name = "lockFavs"; lockFavs.value = ""; lockFavs.id = "lockFavs"; if (localStorage.getItem("LockFavs") == "Y") { lockFavs.checked = "Yes"; } else { lockFavs.checked = ""; } const lockFavsLabel = document.createElement("label"); lockFavsLabel.htmlFor = "lockFavsLabel"; lockFavsLabel.appendChild(document.createTextNode("Lock Favorites")); if ($(".mouseCrownsView-group-mouse-favouriteButton").length > 0) { toolBar.appendChild(lockFavs); toolBar.appendChild(lockFavsLabel); } // Community Ranks CB const communityRanks = document.createElement("input"); communityRanks.type = "checkbox"; communityRanks.name = "communityRanks"; communityRanks.value = ""; communityRanks.id = "communityRanks"; communityRanks.checked = ""; if (localStorage.getItem("ShowCommunityRanks") == "Y") { communityRanks.checked = "Yes"; } else { communityRanks.checked = ""; } const communityRanksLabel = document.createElement("label"); communityRanksLabel.htmlFor = "communityRanksLabel"; communityRanksLabel.appendChild( document.createTextNode("Show Community Ranks ") ); toolBar.appendChild(communityRanks); toolBar.appendChild(communityRanksLabel); //Copy Crown Button const copyCrownsButton = document.createElement("button"); copyCrownsButton.id = "copyCrownsButton"; if ($(".mouseCrownsView-group-mouse-favouriteButton").length > 0) { copyCrownsButton.addEventListener("click", copyMyCrowns) } else { copyCrownsButton.addEventListener("click", copyCrowns) } $(copyCrownsButton).attr('title', 'Copy Crowns to Clipboard'); toolBar.appendChild(copyCrownsButton); $(copyCrownsButton).css({ 'background-image': "url('https://image.flaticon.com/icons/svg/1250/1250214.svg')", 'background-repeat': 'no-repeat', 'background-size': 'contain', 'width': '25px', 'height': '25px', }); // Last let crownBreak = $('.mouseCrownsView-group.favourite'); crownBreak.append(toolBar); $(".toolBar").css({ 'float': "right", }); } /********** Lock Favs **********/ $(document).on("change", "#lockFavs", function() { if ( window.location.href.includes("profile.php") && $(".mousehuntHud-page-tabHeader.kings_crowns").hasClass("active") ) { // Check to see if the cb was JUST checked if (this.checked) { // Put the checked value into storage localStorage.setItem("LockFavs", "Y"); lockFavs.checked = "Yes"; lockFavorites(); } else { // Put the checked value into storage localStorage.setItem("LockFavs", "N"); lockFavs.checked = ""; unlockFavorites(); } } }); function lockFavorites() { localStorage.setItem("Lock Favorites", "Y"); if ($(".mouseCrownsView-group-mouse-favouriteButton").length < 0) { localStorage.setItem("LockFavs", "N"); lockFavs.checked = ""; return; } const allMice = $(".mouseCrownsView-group-mouse").find('.mouseCrownsView-group-mouse-favouriteButton'); allMice.css("pointer-events", "none"); $(".mouseCrownsView-crown.favourite").css( "background", "url('https://image.flaticon.com/icons/svg/204/204310.svg') no-repeat left top" ); } function unlockFavorites() { localStorage.setItem("Lock Favorites", "N"); const allMice = $(".mouseCrownsView-group-mouse").find('.mouseCrownsView-group-mouse-favouriteButton'); allMice.css("pointer-events", "auto"); $(".mouseCrownsView-crown.favourite").css({ 'background-image': "url('https://www.mousehuntgame.com/images/ui/camp/trap/star_favorite.png')", 'display': 'inline-block', 'vertical-align': 'middle', 'width': '50px', 'height': '50px', 'margin-right': '5px', 'background-repeat': 'no-repeat', 'background-position': '50% 50%', 'background-size': 'contain' }); } /********** Community Ranks **********/ $(document).on("change", "#communityRanks", function() { if ( window.location.href.includes("profile.php") && $(".mousehuntHud-page-tabHeader.kings_crowns").hasClass("active") ) { // Check to see if the cb was JUST checked if (this.checked) { // Put the checked value into storage localStorage.setItem("ShowCommunityRanks", "Y"); communityRanks.checked = "Yes"; showCommunityRanks(); } else { // Put the checked value into storage localStorage.setItem("ShowCommunityRanks", "N"); communityRanks.checked = ""; hideCommunityRanks(); } } }); function showCommunityRanks() { const debug = localStorage.getItem('ws.debug'); const totalMice = localStorage.getItem('ws.mh.pfp.numMice'); if ($(".crownheader.crownheadercommunity").length > 0) { return; } const crownBreak = $(".mouseCrownsView-group.favourite"); const communityCrownHeader = $( "