Autostrife

Automatically strifes on the Overseer project.

当前为 2014-10-23 提交的版本,查看 最新版本

您需要先安装一个扩展,例如 篡改猴Greasemonkey暴力猴,之后才能安装此脚本。

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

您需要先安装一个扩展,例如 篡改猴暴力猴,之后才能安装此脚本。

您需要先安装一个扩展,例如 篡改猴Userscripts ,之后才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey,才能安装此脚本。

您需要先安装用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Autostrife
// @namespace    http://gigapause.com/
// @version      0.9.1
// @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 = $('#banner > div.intercross > span > div.pined');
        var encountercontainer = $('#banner > div.intercross > div.lefy > span');
        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 = $('#banner > div.intercross > div.lefy > span');
        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.");
        var encountercontainer3 = $('#banner > div.intercross > div.lefy > span');
        var encounters3 = encountercontainer3.html();
        encounters3 = encounters3.replace( /^\D+/g, '');
        if (Number(encounters3) === 0 && getCookie('autostrife') == "doGrind" ) {
            console.log("====> There are no encounters left. Grinding is over.");
            unsetCookie('autostrife');
        }
    }
}

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