Greasy Fork

MH - Iceberg Progress Info

Originally found at http://mhutilitiesbyshk.altervista.org/scripts.php

目前为 2020-04-17 提交的版本。查看 最新版本

// ==UserScript==
// @name      MH - Iceberg Progress Info
// @author    Giuseppe Di Sciacca (Improved by Hazado)
// @version   1.016
// @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
// ==/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(jQuery('div.depth span.turnsTaken').html().replace(',',''),10);
    jQuery('div.chest').mouseover(function(){
        jQuery('div.icebergPercentageContainer').hide();
        if(jQuery(this)[0].innerHTML.indexOf(' hunts left)')<0 || huntsDone!=parseInt(jQuery('div.depth span.turnsTaken').html().replace(',',''),10))
        {
            var stage=jQuery('div.depth div.currentPhase').html();
            //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='<br/>Required Average: ';
            if(getAverageFeet()>=avgForChest)
                averageMsg+='<span style="color:green">';
            else
                averageMsg+='<span style="color:red">';
            averageMsg+=avgForChest+'</span>';
            averageMsg+="<br/>Minimum average needed in the next hunts: "+avgToHit;
            jQuery(this)[0].children[0].innerHTML = jQuery(this)[0].children[0].innerHTML.replace('</b> to earn','</b> ('+huntsLeft+' hunts left) to earn')+averageMsg;
        }
    });
    jQuery('div.chest').mouseout(function(){
        jQuery('div.icebergPercentageContainer').show();
    });
    //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(){
        jQuery('div.icebergPercentageContainer').hide();
        if(jQuery(this).children('div.help').length==0)
        {
            jQuery(this).append('<div class="help"></div>');
            //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=jQuery('div.depth div.currentPhase').html();
        var feet=parseInt(jQuery('span.user_progress_container span.user_progress').html().replace(',',''),10);
        var huntsDone=parseInt(jQuery('div.depth span.turnsTaken').html().replace(',',''),10);
        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='<span style="font-weight:bold;">Deep Mouse</span>:';
        averageMsg+='<br/>Required Average: ';
        if(getAverageFeet()>=avgForChest)
            averageMsg+='<span style="color:green">';
        else
            averageMsg+='<span style="color:red">';
        averageMsg+=avgForChest+'</span>';
        if(avgToHit>0)
            averageMsg+='<br/>Minimum average needed in the next hunts: '+avgToHit;
        else
            averageMsg+='<br/>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('div.icebergPercentageContainer').show();
        jQuery(this).children('div.help').hide();
    });
    function calculateIcebergPercentageProgress(){
        var feet=parseInt(jQuery('span.user_progress_container span.user_progress').html().replace(',',''),10);
        var stagePerc=0;
        var stageMissing=0;
        var totalPerc=(Math.round(feet/0.18))/100;
        var totalAvg=getAverageFeet(feet);
        var totalMissing=1800-feet;
        var stage=jQuery('div.depth div.currentPhase').html();
        var progressMessage = '';
        if(stage=='Hidden Depths')
        {
            stagePerc=(Math.round(feet/0.02))/100;
            stageMissing=200-feet;
            progressMessage = '<br /><b>Stage progress:</b> '+stagePerc+'% - '+stageMissing+' feet to go';
        }
        else if(stage=="Icewing's Lair" || stage=='The Deep Lair')
        {
            progressMessage = '<br /><b>Stage progress:</b> 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 = '<b>Total progress:</b> '+totalPerc+'% - '+totalMissing+' feet to go<br /><b>Stage progress:</b> '+stagePerc+'% - '+stageMissing+' feet to go';
            else if(stage=='General')
                progressMessage = '<b>Total progress:</b> '+totalPerc+'% - '+totalMissing+' feet to go<br /><b>Stage progress:</b> 100% - <b>General</b>';
        }

        if(jQuery('div.cutaway div.icebergPercentageContainer').length==0)//need to create the progress div?
            jQuery('div.cutaway').append('<div class="icebergPercentageContainer" title="Average: '+totalAvg+' feet per hunt" style="background: #EEEEEE; border: 1px solid #333333; border-radius: 10px; padding: 4px; color: #000000; position:absolute; z-index:30; top:78px; left:10px; color:#000000;">'+progressMessage+'</div>');
        else//just update it
            jQuery('div.cutaway div.icebergPercentageContainer').html(progressMessage).attr('title','Average: '+totalAvg+' feet per hunt');

        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;
    }
}