Autostrife

Automatically strifes on the Overseer project.

Від 23.10.2014. Дивіться остання версія.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Violentmonkey to install this script.

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

You will need to install an extension such as Tampermonkey to install this script.

You will need to install a user script manager extension to install this script.

(У мене вже є менеджер скриптів, дайте мені встановити його!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(I already have a user style manager, let me install it!)

// ==UserScript==
// @name         Autostrife
// @namespace    http://gigapause.com/
// @version      0.9
// @description  Automatically strifes on the Overseer project.
// @author       capableResistor
// @grant        none
// @match        http://*.theoverseerproject.com/*
// @require      http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js
// ==/UserScript==

function strife(){
    createInput();
    if($('#aspect').length){
        var healthcontainer = $('.pined');
        var encountercontainer = $('.c3');
        var health = healthcontainer.html();
        var encounters = encountercontainer.html();
        health = health.replace( /^\D+/g, '');
        health = health.replace('%','');
        encounters = encounters.replace( /^\D+/g, '');
        
        document.title = "H: " + Number(health) + "%" + " E: " + Number(encounters) + ". Overseer";
        
        if (getCookie('autostrife') === "") {
            console.log("====> Autostrife cookie not set. Not autostrifing.");
        } else if (getCookie('autostrife') == "doStrife" || getCookie('autostrife') == "doGrind") {
            if(Number(health) < 20  && getCookie('autostrife') == "doStrife") {
                //abscond();
                console.log("====> Too dangerous to autostrife (Health below 20%). Manual intervention required.");
            } else {
                attack();
            }
            if (Number(health) < 5 && getCookie('autostrife') == "doGrind") {
                console.log("====> Looks like you're in trouble. Get healed above 5% before you attempt grinding and sure you're taking on enemies you're very sure you can defeat easily.");
            } else {
                attack();
            }
        } else {
            console.log("====> Error: Cookie setting mismatch. Resetting cookie.");
            unsetCookie('autostrife');
        }
    } else if ($('#canner a').length > 0 && $.trim($('#canner a').text()) == "Strife again" && getCookie('autostrife') == "doStrife") {
        console.log("====> Strife concluded.");
        unsetCookie('autostrife');
    } else if ($('#canner a').length > 0 && $.trim($('#canner a').text()) == "Strife again" && getCookie('autostrife') == "doGrind") {
        console.log("====> Strife concluded, but grind mode is on.");
        window.location.href = 'strife.php';
    } else if ($('input[type="submit"][value="Fight these enemies again!"]').length && getCookie('autostrife') == "doGrind") {
        console.log("====> On strife init page, and autoGrind is on.");
        var encountercontainer2 = $('.c3');
        var encounters2 = encountercontainer2.html();
        encounters2 = encounters2.replace( /^\D+/g, '');
        if (Number(encounters2) === 0) {
            console.log("====> However, there are no encounters left. Grinding is over.");
            unsetCookie('autostrife');
        } else  {
            console.log("====> We have " + Number(encounters2) + " enounter(s) to work with.");
            initiate();
        }
    } else {
        console.log("====> Nothing to do right now.");
    }
}

function setCookie(cname, cvalue, exdays){
    var d = new Date();
    d.setTime(d.getTime() + (exdays*24*60*60*1000));
    var expires = "expires="+d.toUTCString();
    document.cookie = cname + "=" + cvalue + "; " + expires;
}

function unsetCookie(cname){
    document.cookie = cname + "=''; expires=-1";
}

function getCookie(cname){
    var name = cname + "=";
    var ca = document.cookie.split(';');
    for(var i=0; i<ca.length; i++) {
        var c = ca[i];
        while (c.charAt(0)==' ') c = c.substring(1);
        if (c.indexOf(name) != -1) return c.substring(name.length,c.length);
    }
    return "";
}

function createInput(){
    var atbutton = $('input[type="submit"][value="Abscond"]');
    var userinfo = $('#banner > div.intercross > span > div.lined > a');
    if(atbutton.length > 0){
        atbutton.after($('</br><input type="button" id="autostrife" name="astrife" value="autoStrife();"><input type="button" id="autogrind" name="agrind" value="autoGrind();">'));
        document.getElementById('autostrife').addEventListener("click", autoStrife, false);
        document.getElementById('autogrind').addEventListener("click", autoGrind, false);
    }
    if(userinfo.length > 0){
        userinfo.after($('<span class="rhyme slam astop" id="stop">STOPAUTO();</span>'));
        userinfo.after($('<style>#stop {\ncolor: #000;\nmargin-left: auto;\nmargin-right: auto;\nmargin-top: 5px;\n}\n#stop:active {\nbackground-color: #444;\ncolor: #FFF;\n}\n#stop:hover {\noutline: thin red solid\n}</style>'));
        document.getElementById('stop').addEventListener("click", stop, false);
    }
}

function attack(){
    var atbutton = $('input[type="submit"][value="Attack"]');
    atbutton.trigger("click");
}

function abscond(){
    var abbutton = $('input[type="submit"][value="Abscond"]');
    abbutton.trigger("click");
}

function initiate(){
    var lastbutton = $('input[type="submit"][value="Fight these enemies again!"]');
    lastbutton.trigger("click"); 
}

function autoStrife(){
    setCookie('autostrife', 'doStrife', '1');
    window.location.href = 'strife.php';
}

function autoGrind(){
    setCookie('autostrife', 'doGrind', '7');
    window.location.href = 'strife.php';
}

function stop(){
    unsetCookie('autostrife');
    console.log("====> Unsetting autostrife and autogrind.");
}

setTimeout( strife(), 3000 );