Gladiatus Auto Dungeon click

gladiatus auto dungeon

目前為 2017-02-23 提交的版本,檢視 最新版本

// ==UserScript==
// @name        Gladiatus Auto Dungeon click
// @description gladiatus auto dungeon
// @include     https://s*.gladiatus.gameforge.*/game/index.php?mod=dungeon*
// @include     https://s*.gladiatus.gameforge.*/game/index.php?mod=reports&submod=showCombatReport*t=1*
// @include     http://s*.gladiatus.gameforge.*/game/index.php?mod=dungeon*
// @include     http://s*.gladiatus.gameforge.*/game/index.php?mod=reports&submod=showCombatReport*t=1*
// @author      ZaharX97
// @version  	0.97
// @namespace   https://greasyfork.org/users/104906
// ==/UserScript==
window.addEventListener("pageshow", calculateRuntime);
var refreshInc = setTimeout(function(){ window.location.reload(true); }, 10000);
//console.log("this is after load event");

function main () {
    var elemLink, dungeonLink, time, x, elemFights, elemDungeons;
    elemLink = document.getElementsByClassName("cooldown_bar_link");
    dungeonLink = elemLink[1].href;
    time = getRemainingTime();
    if(isNaN(time)){
        if(window.location.href != dungeonLink){
            x = getRndInteger( 0, 2899 );
            setTimeout(function(){ console.log("[GAD]: going to dungeon"); window.location.assign(dungeonLink); }, 2510 + x);
            return;
        }
        elemFights = document.getElementsByTagName("area");
        //console.log("fights length= " + elemFights.length );
        x = getRndInteger( 0, 3281 );
        if(elemFights.length)
            setTimeout( function(){ clickNextFight(elemFights[elemFights.length - 1]); }, x);
        else{
            elemDungeons = document.getElementsByClassName("button1");
            for(var i = elemDungeons.length - 1 ; i >= 0 ; i--)
                if( elemDungeons[i].type == "submit" ){
                    setTimeout( function(){ clickNextFight(elemDungeons[i]); }, x);
                    return;
                }
        }
    }
    else{
        setTimeout( function(){ console.log( "[GAD]: " + time + " passed, going to dungeon" ); window.location.assign(dungeonLink); }, time + 5000 );
        return;
    }
}

function getRemainingTime(){
    var elemTime, timeText, x, time;
    elemTime = document.getElementById("cooldown_bar_text_dungeon");
    timeText = elemTime.innerText;
    x = getRndInteger( 1, 4 );
    time = timeText[0]*3600 + timeText[2]*10*60 + timeText[3]*60 + timeText[5]*10 + timeText[6]*1 + x*1;
    //console.log( timeText[0]*3600 + " " + timeText[2]*10*60 + " " + timeText[3]*60 + " " + timeText[5]*10 + " " + timeText[6] + " " + x + " timp= " + time);
    time = time*1000;
    console.log( "[GAD]: going to dungeon in " + time + "ms" );
    return time;
}

function clickNextFight(elemFight){
    elemFight.click();
}

function getRndInteger(min, max) {
    return Math.floor(Math.random() * (max - min + 1) ) + min;
}

function calculateRuntime(){
    var sRuntime = Date.now();
    var eRuntime;
    clearTimeout(refreshInc);
    main();
    eRuntime = Date.now() - sRuntime;
    console.log("[GAD] runtime: " + eRuntime + "ms" );
}