// ==UserScript== // @name MH - Iceberg Progress Info // @author Giuseppe Di Sciacca (Improved by Hazado) // @version 1.018 // @description Originally found at http://mhutilitiesbyshk.altervista.org/scripts.php // @require https://code.jquery.com/jquery-1.12.4.min.js // @include http://mousehuntgame.com/* // @include https://mousehuntgame.com/* // @include http://www.mousehuntgame.com/* // @include https://www.mousehuntgame.com/* // @include http://apps.facebook.com/mousehunt/* // @include https://apps.facebook.com/mousehunt/* // @namespace https://greasyfork.org/users/149039 // @downloadURL none // ==/UserScript== if(user.environment_name=='Iceberg') doIcebergPluginStuff(); // the guts of this userscript function doIcebergPluginStuff() { jQuery('div.depth').css('cursor','pointer'); jQuery('div.depth').click(function(){ if(jQuery('div.cutawayClippingMask').css('overflow')=='hidden') { jQuery('div.depth').css('z-index',30); jQuery('div.cutawayClippingMask div.icebergContainer').css('z-index',30); jQuery('div.cutawayClippingMask').css('overflow','visible'); } else { jQuery('div.depth').css('z-index',3); jQuery('div.cutawayClippingMask div.icebergContainer').css('z-index',2); jQuery('div.cutawayClippingMask').css('overflow','hidden'); } }); jQuery(document).keyup(function(e){ if(e.keyCode==27) { jQuery('div.depth').css('z-index',3); jQuery('div.cutawayClippingMask div.icebergContainer').css('z-index',2); jQuery('div.cutawayClippingMask').css('overflow','hidden'); } }); var feet=calculateIcebergPercentageProgress(); setInterval(function(){ if(parseInt(jQuery('span.user_progress_container span.user_progress').html().replace(',',''),10)!=feet) feet=calculateIcebergPercentageProgress(); },15000);//checks if there's the need to update every 15 seconds var huntsDone=parseInt(user.quests.QuestIceberg.turns_taken); jQuery('div.chest').mouseover(function(){ if(jQuery(this)[0].innerHTML.indexOf(' hunts left)')<0 || huntsDone!=parseInt(jQuery('div.depth span.turnsTaken').html().replace(',',''),10)) { var stage=user.quests.QuestIceberg.current_phase; //if I'm updating I remove the old message in the brackets in order to add it again if(jQuery(this)[0].innerHTML.indexOf(' hunts left)')>0) jQuery(this)[0].innerHTML = jQuery(this)[0].innerHTML.replace(/\(\d{1,3}/,'').replace(' hunts left) ',''); //write the number of hunts left for the chest in the message var huntsForChest=parseInt(jQuery(this)[0].children[0].children[0].children[0].textContent.replace('Hunt #',''),10); huntsDone=parseInt(user.quests.QuestIceberg.turns_taken); huntsForChest-=2;//huntsForChest-2=>at least 1 hunt for icewing and 1 for the last general that doesn't give you any feet var huntsLeft=huntsForChest-huntsDone; if(huntsLeft<0) huntsLeft=0; var avgForChest=(Math.round(180000/huntsForChest))/100; var feet=parseInt(user.quests.QuestIceberg.user_progress); if(feet<1800) var avgToHit=(Math.round((1800-feet)*100/huntsLeft))/100; else var avgToHit=0; var averageMsg='
Required Average: '; if(getAverageFeet()>=avgForChest) averageMsg+=''; else averageMsg+=''; averageMsg+=avgForChest+''; averageMsg+="
Minimum average needed in the next hunts: "+avgToHit; jQuery(this)[0].children[0].innerHTML = jQuery(this)[0].children[0].innerHTML.replace(' to earn',' ('+huntsLeft+' hunts left) to earn')+averageMsg; } }); //div.waterline has z-index:4, div.iceberg has z-index 3, so I shouldn't be able to intercept anything on div.iceberg //cange z-index to 4 then jQuery('div.icebergContainer div.iceberg').css('z-index',4); jQuery(document).on('mouseover','div.icebergContainer div.iceberg',function(){ if(jQuery(this).children('div.help').length==0) { jQuery(this).append('
'); //give same style as .icebergHud .timeline .chest .help jQuery(this).children('div.help').attr('style','background: #EEEEEE; border: 1px solid #333333; border-radius: 10px; color: #000000; display: none; left: -65px; padding: 10px; position: absolute; top: 20px; width: 150px;'); //adjust a bit jQuery(this).children('div.help').css('top','34px').css('left','-55px'); } var stage=user.quests.QuestIceberg.current_phase; var feet=parseInt(user.quests.QuestIceberg.user_progress); var huntsDone=parseInt(user.quests.QuestIceberg.turns_taken); if(feet<1800 || (feet==1800 && stage=='General') ) huntsForChest=247;//250-deep mouse-icewing-general else huntsForChest=248;//250-deep mouse-icewing //not 249 since the div.iceberg disappears after icewing var huntsLeft=huntsForChest-huntsDone; var avgForChest=(Math.round(200000/huntsForChest))/100; if(huntsLeft>0) var avgToHit=(Math.round((2000-feet)*100/huntsLeft))/100; else var avgToHit=0; //build message var averageMsg='Deep Mouse:'; averageMsg+='
Required Average: '; if(getAverageFeet()>=avgForChest) averageMsg+=''; else averageMsg+=''; averageMsg+=avgForChest+''; if(avgToHit>0) averageMsg+='
Minimum average needed in the next hunts: '+avgToHit; else averageMsg+='
Hunt #'+huntsDone+', you cannot reach the Deep Mouse anymore :('; jQuery(this).children('div.help').html(averageMsg).show(); }); jQuery(document).on('mouseout','div.iceberg',function(){ jQuery(this).children('div.help').hide(); }); function calculateIcebergPercentageProgress(){ var feet=parseInt(user.quests.QuestIceberg.user_progress); var stagePerc=0; var stageMissing=0; var totalPerc=(Math.round(feet/0.18))/100; var totalAvg=getAverageFeet(feet); var totalMissing=1800-feet; var stage=user.quests.QuestIceberg.current_phase; var progressMessage = ''; if(stage=='Hidden Depths') { stagePerc=(Math.round(feet/0.02))/100; stageMissing=200-feet; progressMessage = '
Stage progress: '+stagePerc+'% - '+stageMissing+' feet to go'; } else if(stage=="Icewing's Lair" || stage=='The Deep Lair') { progressMessage = '
Stage progress: 100%'; } else { if(stage=='Treacherous Tunnels') { stagePerc=(Math.round(feet/0.03))/100; stageMissing=300-feet; } else if(stage=='Brutal Bulwark') { stagePerc=(Math.round((feet-300)/0.03))/100; stageMissing=600-feet; } else if(stage=='Bombing Run') { stagePerc=(Math.round((feet-600)/0.1))/100; stageMissing=1600-feet; } else if(stage=='The Mad Depths') { stagePerc=(Math.round((feet-1600)/0.02))/100; stageMissing=1800-feet; } if(stagePerc>0 || stageMissing>0)//if in a known stage progressMessage = 'Total progress: '+totalPerc+'% - '+totalMissing+' feet to go
Stage progress: '+stagePerc+'% - '+stageMissing+' feet to go'; else if(stage=='General') progressMessage = 'Total progress: '+totalPerc+'% - '+totalMissing+' feet to go
Stage progress: 100% - General'; } if(jQuery('div.cutaway div.depth span.averageTurns').length==0){//need to create the progress div? jQuery('div.cutaway div.depth span.turnsTaken')[0].outerHTML = jQuery('div.cutaway div.depth span.turnsTaken')[0].outerHTML.replace('
',"
- Avg: "+totalAvg+" feet/hunt"); jQuery('div.cutaway div.depth').append("Total: "+totalPerc+"% - "+totalMissing+" feet to go
Stage: "+stagePerc+"% - "+stageMissing+" feet to go
"); } else{//just update it jQuery('div.cutaway div.depth span.averageTurns')[0].innerHTML = " - Avg: "+totalAvg+" ft/hunt"; jQuery('div.cutaway div.depth span.TotalProgress')[0].innerHTML = "Total: "+totalPerc+"% - "+totalMissing+" feet to go
Stage: "+stagePerc+"% - "+stageMissing+" feet to go"; } return feet; } function getAverageFeet(feet){ if(feet==undefined)//the only purpose of this parameter is for optimization, to avoid retrieving it everytime feet=parseInt(jQuery('span.user_progress_container span.user_progress').html().replace(',',''),10); var totalHunts=parseInt(jQuery('div.depth span.turnsTaken').html().replace(',',''),10); if(totalHunts==0) totalHunts=1;//for average, just to avoid division by zero return (Math.round((feet*100)/totalHunts))/100; } }