Autostrife

Automatically strifes on the Overseer project.

目前為 2014-10-22 提交的版本,檢視 最新版本

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

function strife(){
    if($('#aspect').length){
        createInput();
        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"){
            if(Number(health) < 20 ) {
                //abscond();
            }else{
                attack();
            }
        }
    } else if($('#canner a').length > 0 && $.trim($('#canner a').text()) == "Strife again"){
        unsetCookie('autostrife');
        console.log("Strife concluded.");
    }else{
        console.log("Something is amiss. Are you logged in?");
    }    
}

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="Attack"]');
    atbutton.after($('<input type="button" id="autostrife" name="astrife" value="autoStrife();">'));
    document.getElementById('autostrife').addEventListener("click", autoStrife, 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 autoStrife(){
    setCookie('autostrife', 'doStrife', '1');
    window.location.href = 'strife.php';
}

setTimeout( strife(), 3000 );