Gladiatus Auto Dungeon click

gladiatus auto dungeon

当前为 2017-02-24 提交的版本,查看 最新版本

// ==UserScript==
// @name        Gladiatus Auto Dungeon click
// @description gladiatus auto dungeon
// @include     *://*s*.gladiatus.gameforge.*/game/index.php?mod=*
// @include     *://*s*.gladiatus.gameforge.*/game/index.php?mod=reports&submod=showCombatReport*t=1*
// @author      ZaharX97
// @version  	1.08
// @namespace   https://greasyfork.org/users/104906
// @grant GM_getValue
// @grant GM_setValue
// @grant GM_listValues
// ==/UserScript==
var statusLocal = GM_getValue("status", true);
var refreshInc = setTimeout(function(){ window.location.reload(true); }, 10000);
window.addEventListener("pageshow", calculateRuntime);
addAutoDungeonButton();

function main () {
    var i, lengthFak, elemLink, dungeonLink, time, x, elemFights, elemLvlup;
    elemLink = document.getElementById("linknotification");
    if(isValid(elemLink)){
        elemLink.click();
        x = getRndInteger( 0, 2899 );
        setTimeout(function(){ window.location.reload(true); }, 2510 + x);
        return;
    }
    elemLink = document.getElementById("linkLoginBonus");
    if(isValid(elemLink)){
        elemLink.click();
        x = getRndInteger( 0, 2899 );
        setTimeout(function(){ window.location.reload(true); }, 2510 + x);
        return;
    }
    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");
        x = getRndInteger( 0, 3281 );
        if(isValid(elemFights[0])){
            setTimeout( function(){ elemFights[elemFights.length - 1].click(); }, x);
            console.log("here?");
            return;
        }
        else{
            elemFights = document.getElementsByClassName("button1");
            if(isValid(elemFights[0])){
                for(i = elemFights.length - 1 ; i >= 0 ; i--)
                    if( elemFights[i].type == "submit" ){
                        setTimeout( function(){ elemFights[i].click(); }, x);
                        console.log("or here?");
                        return;
                    }
            }
            else setTimeout(function(){ console.log("[GAD]: teleporting to dungeon"); window.location.assign(dungeonLink); }, 2510 + x);
        }
    }
    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 isValid(x){
    if( (x === undefined) || (x === null) )
        return false;
    return true;
}

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

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

function addAutoDungeonButton(){
    var elemTarget = document.getElementsByClassName("contentItem");
    if(!elemTarget[0])
        elemTarget = document.getElementsByClassName("reportWin");
    var elemMyButton = document.createElement("div");
    elemMyButton.setAttribute("id", "GADonoffbutton");
    elemMyButton.style.marginTop = "7px";
    var elemNewChild = document.createElement("div");
    elemNewChild.setAttribute("id", "GADoutline");
    if(statusLocal)
        elemNewChild.style.backgroundImage = "url(https://s17-ro.gladiatus.gameforge.com/game/9019/img/ui/bar_fill_green.jpg)";
    else
        elemNewChild.style.backgroundImage = "url(https://s17-ro.gladiatus.gameforge.com/game/9019/img/ui/bar.jpg)";
    elemNewChild.style.backgroundRepeat = "no-repeat";
    elemNewChild.style.backgroundSize = "138px 19px";
    elemNewChild.style.backgroundPosition = "center";
    elemNewChild.innerText = (statusLocal)?"AUTO DUNGEON ON":"AUTO DUNGEON OFF";
    elemNewChild.style.textAlign = "center";
    elemNewChild.style.color = "#c8b38a";
    elemNewChild.style.fontWeight = "bold";
    elemNewChild.style.width = "138px";
    elemNewChild.style.marginLeft = elemTarget[0].scrollWidth/2 - 138/2 + "px";
    elemNewChild.style.marginRight = elemTarget[0].scrollWidth/2 + 138/2 + "px";
    elemNewChild.style.cursor = "pointer";
    elemNewChild.style.outlineColor = "#ffff00";
    elemNewChild.style.outlineWidth = "1px";
    elemNewChild.addEventListener("mouseover", function() {
        document.getElementById("GADoutline").style.outlineStyle = "solid";
    });
    elemNewChild.addEventListener("mouseout", function() {
        document.getElementById("GADoutline").style.outlineStyle = "none";
    });
    elemNewChild.addEventListener("click", function() {
        GM_setValue("status", !statusLocal);
        window.location.reload();
    });
    elemMyButton.appendChild(elemNewChild);
    elemNewChild = document.createElement("br");
    elemMyButton.appendChild(elemNewChild);
    elemTarget[0].parentElement.insertBefore(elemMyButton, elemTarget[0]);
}