HP/PP greasemonkey script

Off-topic posts about whatever, including off-the-wall posts about being on walls.

Moderator: Moderators

Post Reply
Harry Dresden
Posts: 1395
Joined: Tue Feb 12, 2008 1:22 pm
Contact:

HP/PP greasemonkey script

Post by Harry Dresden »

Well, now it doesn't work right; hides chip count. Plus, it was already wonky with Nardo's re-buff script.

So, as a reward for someone fixing it, I'm offering one star for a script that works with everything else and has the right colors - red bar for HP, blue bar for PP, and white borders and numbers.
Satan
Posts: 1855
Joined: Mon Nov 19, 2007 6:29 pm
Location: Florida
Contact:

Re: HP/PP greasemonkey script

Post by Satan »

Harry Dresden wrote:Well, now it doesn't work right; hides chip count. Plus, it was already wonky with Nardo's re-buff script.

So, as a reward for someone fixing it, I'm offering one star for a script that works with everything else and has the right colors - red bar for HP, blue bar for PP, and white borders and numbers.
It's potentially impossible to make it work with 'everything', but I can make an attempt at this. I'll check it out now and see if it works standalone. If it does, I'll need to know which scripts you're using to isolate what's doing it.
Leader of PFE league. If you wish to worship me, ask me about joining my secondary league Cult of Satan (the largest league in the game!).
Harry Dresden
Posts: 1395
Joined: Tue Feb 12, 2008 1:22 pm
Contact:

Re: HP/PP greasemonkey script

Post by Harry Dresden »

Many thanks to Satan for completing a script. It required a reworking of Nardo's to work with the re-buff, but it's nice seeing my chip total again.
Satan
Posts: 1855
Joined: Mon Nov 19, 2007 6:29 pm
Location: Florida
Contact:

Re: HP/PP greasemonkey script

Post by Satan »

Here's the modified version of the TH HP/PP script, with the original colors, and the chips fix.

Code: Select all

// ==UserScript==
// @name         TH HP_PP Status
// @namespace    TwilightHeroes
// @description    Graphical Status for HP and PP
// @include        *twilightheroes.com/nav.php*
// @include        *twilightheroes.com/index.php*
// @include        *twilightheroes.com/account.php*
// ==/UserScript==
/************ KEEP THIS HERE (IN ORDER) FOR AUTO UPDATER *************/
const TH_PStat_ScriptName = 'TH HP_PP Status';
const TH_PStat_Version = 1.13;
const TH_PStat_ReleaseNotes = "Formatting on account page";
const TH_PStat_OutOfDateName = 'TH_PStat_OutOfDate';
/*************************/

//Modified from routine written by JHunz
function TH_PStat_CheckForUpdates(label, img)
{
    if (label)
    {
        label.innerHTML = '[checking for updates...]';
        if (img)
        {
            img.style.display = 'inline';
        }
    }
    GM_setValue(TH_PStat_OutOfDateName,'');
    var strScriptSrc = 'http://computertrinkets.googlepages.com/' + TH_PStat_ScriptName.replace(/ /g,'') + '.user.js';
    var updateExists = null;
    GM_xmlhttpRequest({
        method: 'GET',
        url: strScriptSrc,
        onload: function(responseDetails)
                {
                    var matches = responseDetails.responseText.match(/const TH_PStat_Version[ ]?=[ ]?([\d\.]+);(\s+const TH_PStat_ReleaseNotes[ ]?=[ ]?"(.*)";)?/);
                    if (matches)
                    {
                        var curVersionNum = parseFloat(matches[1]);
                        GM_setValue(TH_PStat_OutOfDateName,(curVersionNum && curVersionNum > TH_PStat_Version && curVersionNum >= 0));
                        if (matches[3])
                        {
                            var strReleaseNotes = matches[3];
                        }
                        if (img){img.style.display = 'none';}
                        if(GM_getValue(TH_PStat_OutOfDateName,false))
                        {
                            if (label){label.innerHTML = '[update available]';}
                            if (confirm('A new version of ' + TH_PStat_ScriptName + ' is available.' +
                                ('\nYour Version:' + TH_PStat_Version + '\nLatest Version:' + curVersionNum) +
                                ( strReleaseNotes ? '\nRelease Notes: ' + strReleaseNotes : '') + '\nUpdate now?'))
                            {
                                if (label){label.innerHTML = '[Update installed.  Please refresh your browser.]';}
                                if(parent) {parent.location = strScriptSrc;}
                                else {self.location = strScriptSrc;}
                            }
                        }
                        else
                        {
                            if (label){label.innerHTML = '[no new updates]';}
                        }
                    }
                    else
                    {
                        GM_log("Unable to find current version of " + TH_PStat_ScriptName + " script");
                    }
                }
    });
}

function TH_PStat_AddGlobalStyle(css)
{
    var head = document.getElementsByTagName('head')[0];
    if (!head) { return; }
    var style = document.createElement('style');
    style.type = 'text/css';
    style.innerHTML = css;
    head.appendChild(style);
}

var TH_PStat_HideHeadersName = 'TH_PStat_HideHeaders';
var TH_PStat_HideHeaders = GM_getValue(TH_PStat_HideHeadersName, true);
var strHP, strPP;
var TH_PStatPanelVisibleName = 'TH_PStat_PanelVisible';

if (String(self.location).toUpperCase().indexOf("NAV.PHP") > -1) //loads in nav page
{
    var TH_PStat_totWidth = 10;
    var strongs = document.getElementsByTagName('strong');
    var brHP, brPP;
    for (var i = 0; i < strongs.length; i++)
    {
        if (strongs[i].innerHTML == "HP:")
        {
            strHP = strongs[i];
            strHP.setAttribute('id','strHP');
            brHP = strHP.nextSibling.nextSibling;
        }
        if (strongs[i].innerHTML == "PP:")
        {
            strPP = strongs[i];
            strHP.setAttribute('id','strPP');
            brPP = strPP.nextSibling.nextSibling;
        }
    }
    //Get HP
    var HP = document.getElementById('hpstring');
    var HPdata = HP.innerHTML;
    HP.parentNode.removeChild(HP);
    GM_log(HP);
    var HPs = HPdata.split("/");
    var curHP = HPs[0];
    var totHP = HPs[1];
   
    var tblHPTotal = document.createElement('table');
    tblHPTotal.setAttribute('id','tblHPTotal');
    tblHPTotal.setAttribute('class','tblHP');
    tblHPTotal.setAttribute('cellspacing','0');
    tblHPTotal.setAttribute('cellpadding','0');
    tblHPTotal.innerHTML = "<tr><td class='curHP'></td><td class='totHP'></td><td class='disHPP' id='hpstring'><span id=\"hpstring\">" + HPdata + "</span></td></tr>";
    strHP.parentNode.insertBefore(tblHPTotal, strHP.nextSibling);
    if (TH_PStat_HideHeaders) {strHP.style.display = 'none';}
   
    var cssHP = ".spanHP" +
                "{" +
                    "display: inline;" +
                "}" +
                ".tblHP" +
                "{" +
                    "width: " + TH_PStat_totWidth + "em;" +
                    "border: solid 1px white;" +
                    "height:1.1em;" +
                "}" +
                ".curHP" +
                "{" +
                    "width: " + (curHP/totHP*100) + "%;" +
                    "background-color:rgb("+GM_getValue('TH_PStat_HPColor',"255,0,0")+");" +
                    "color:rgb("+GM_getValue('TH_PStat_HPColor',"255,0,0")+");" +
                "}" +
                ".totHP" +
                "{" +
                    "width: " + ((1-(curHP/totHP))*100) + "%;" +
                    "background-color: none;" +
                "}" +
                ".disHPP" +
                "{" +
                    "position:absolute;" +
                    "color: white;" +
                    "left: "+ ((TH_PStat_totWidth/2)-1) +"em;" +
                    "font-weight: bold;" +
                "}";
    TH_PStat_AddGlobalStyle(cssHP);
   
    //Get PP
    var PP = document.getElementById('ppstring');
    var PPdata = PP.innerHTML;
    PP.parentNode.removeChild(PP);
    var PPs = PPdata.split("/");
    var curPP = PPs[0];
    var totPP = PPs[1];

    var tblPPTotal = document.createElement('table');
    tblPPTotal.setAttribute('id','tblPPTotal');
    tblPPTotal.setAttribute('class','tblPP');
    tblPPTotal.setAttribute('cellspacing','0');
    tblPPTotal.setAttribute('cellpadding','0');
    tblPPTotal.innerHTML = "<tr><td id='curPP' class='curPP'></td><td class='totPP'></td><td class='dispPP' id='ppstring'><span id=\"ppstring\">" + PPdata + "</span></td></tr>";
    strPP.parentNode.insertBefore(tblPPTotal, strPP.nextSibling);
    if (TH_PStat_HideHeaders) {strPP.style.display = 'none';}
   
    var cssPP = ".spanPP" +
                "{" +
                    "display: inline;" +
                "}" +
                ".tblPP" +
                "{" +
                    "width: " + TH_PStat_totWidth + "em;" +
                    "border: solid 1px white;" +
                    "height:1.1em;" +
                "}" +
                ".curPP" +
                "{" +
                    "width: " + (curPP/totPP*100) + "%;" +
                    "background-color:rgb("+GM_getValue('TH_PStat_PPColor',"0,0,255")+");" +
                    "color:rgb("+GM_getValue('TH_PStat_PPColor',"0,0,255")+");" +
                "}" +
                ".totPP" +
                "{" +
                    "width: " + ((1-(curPP/totPP))*100) + "%;" +
                    "background-color: none;" +
                "}" +
                ".disPPP" +
                "{" +
                    "width: 0;" +
                    "position:absolute;" +
                    "color: white;" +
                    "left: "+ ((TH_PStat_totWidth/2)-1) +"em;" +
                    "font-weight: bold;" +
                "}";
    TH_PStat_AddGlobalStyle(cssPP);
}
else
{
    if (String(self.location).toUpperCase().indexOf("INDEX.PHP") > -1) //loads in login page
    {
        TH_PStat_CheckForUpdates();
    }
    else
    {
        if (String(self.location).toUpperCase().indexOf("ACCOUNT.PHP") > -1) //loads in the account page
        {
            var strLoadingImage = 'data:image/gif;base64,R0lGODlhEAAQAMQAAP%2F%2F%2F%2B7u7t3d3bu7u6qqqpmZmYiIiHd3d2ZmZlVVVURERDMzMyIiIhEREQARAAAAAP%2F%2F%2FwAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH%2FC05FVFNDQVBFMi4wAwEAAAAh%2BQQFBwAQACwAAAAAEAAQAAAFdyAkQgGJJOWoQgIjBM8jkKsoPEzgyMGsCjPDw7ADpkQBxRDmSCRetpRA6Rj4kFBkgLC4IlUGhbNQIwXOYYWCXDufzYPDMaoKGBoKb886OjAKdgZAAgQkfCwzAgsDBAUCgl8jAQkHEAVkAoA1AgczlyIDczUDA2UhACH5BAUHABAALAAAAAAPABAAAAVjICSO0IGIATkqIiMKDaGKC8Q49jPMYsE0hQdrlABCGgvT45FKiRKQhWA0mPKGPAgBcTjsspBCAoH4gl%2BFmXNEUEBVAYHToJAVZK%2FXWoQQDAgBZioHaX8igigFKYYQVlkCjiMhACH5BAUHABAALAAAAAAQAA8AAAVgICSOUGGQqIiIChMESyo6CdQGdRqUENESI8FAdFgAFwqDISYwPB4CVSMnEhSej%2BFogNhtHyfRQFmIol5owmEta%2FfcKITB6y4choMBmk7yGgSAEAJ8JAVDgQFmKUCCZnwhACH5BAUHABAALAAAAAAQABAAAAViICSOYkGe4hFAiSImAwotB%2Bsi6Co2QxvjAYHIgBAqDoWCK2Bq6A40iA4yYMggNZKwGFgVCAQZotFwwJIF4QnxaC9IsZNgLtAJDKbraJCGzPVSIgEDXVNXA0JdgH6ChoCKKCEAIfkEBQcAEAAsAAAAABAADgAABUkgJI7QcZComIjPw6bs2kINLB5uW9Bo0gyQx8LkKgVHiccKVdyRlqjFSAApOKOtR810StVeU9RAmLqOxi0qRG3LptikAVQEh4UAACH5BAUHABAALAAAAAAQABAAAAVxICSO0DCQKBQQonGIh5AGB2sYkMHIqYAIN0EDRxoQZIaC6bAoMRSiwMAwCIwCggRkwRMJWKSAomBVCc5lUiGRUBjO6FSBwWggwijBooDCdiFfIlBRAlYBZQ0PWRANaSkED1oQYHgjDA8nM3kPfCmejiEAIfkEBQcAEAAsAAAAABAAEAAABWAgJI6QIJCoOIhFwabsSbiFAotGMEMKgZoB3cBUQIgURpFgmEI0EqjACYXwiYJBGAGBgGIDWsVicbiNEgSsGbKCIMCwA4IBCRgXt8bDACkvYQF6U1OADg8mDlaACQtwJCEAIfkEBQcAEAAsAAABABAADwAABV4gJEKCOAwiMa4Q2qIDwq4wiriBmItCCREHUsIwCgh2q8MiyEKODK7ZbHCoqqSjWGKI1d2kRp%2BRAWGyHg%2BDQUEmKliGx4HBKECIMwG61AgssAQPKA19EAxRKz4QCVIhACH5BAUHABAALAAAAAAQABAAAAVjICSOUBCQqHhCgiAOKyqcLVvEZOC2geGiK5NpQBAZCilgAYFMogo%2FJ0lgqEpHgoO2%2BGIMUL6p4vFojhQNg8rxWLgYBQJCASkwEKLC17hYFJtRIwwBfRAJDk4ObwsidEkrWkkhACH5BAUHABAALAAAAQAQAA8AAAVcICSOUGAGAqmKpjis6vmuqSrUxQyPhDEEtpUOgmgYETCCcrB4OBWwQsGHEhQatVFhB%2FmNAojFVsQgBhgKpSHRTRxEhGwhoRg0CCXYAkKHHPZCZRAKUERZMAYGMCEAIfkEBQcAEAAsAAABABAADwAABV0gJI4kFJToGAilwKLCST6PUcrB8A70844CXenwILRkIoYyBRk4BQlHo3FIOQmvAEGBMpYSop%2FIgPBCFpCqIuEsIESHgkgoJxwQAjSzwb1DClwwgQhgAVVMIgVyKCEAIfkECQcAEAAsAAAAABAAEAAABWQgJI5kSQ6NYK7Dw6xr8hCw%2BELC85hCIAq3Am0U6JUKjkHJNzIsFAqDqShQHRhY6bKqgvgGCZOSFDhAUiWCYQwJSxGHKqGAE%2F5EqIHBjOgyRQELCBB7EAQHfySDhGYQdDWGQyUhADs%3D'
           
            //this requires a div to be created that to both check for updates, and turn on/off the header titles
            var divHPOptions = document.createElement('div');
            divHPOptions.setAttribute('id','divHPOptions');
            divHPOptions.setAttribute('class','divHPOptions');
            divHPOptions.innerHTML = "<h2 style='display:inline;'>HP/PP Status Options</h2> ";
            document.body.insertBefore(divHPOptions, null);
           
            var imgLoading = document.createElement('img');
            imgLoading.setAttribute('id','imgLoading');
            imgLoading.setAttribute('class','imgLoading');
            imgLoading.setAttribute('src',strLoadingImage);
            divHPOptions.insertBefore(imgLoading, null);
           
            var aHPUpdates = document.createElement('a');
            aHPUpdates.setAttribute('id','aHPUpdates');
            aHPUpdates.setAttribute('class','aHPUpdates');
            aHPUpdates.innerHTML = '[check for updates]';
            divHPOptions.insertBefore(aHPUpdates, null);
            aHPUpdates.addEventListener('click', function(event) {
                    TH_PStat_CheckForUpdates(aHPUpdates, imgLoading);
                }, true)
           
            var divHideHeaders = document.createElement('div');
            divHideHeaders.setAttribute('id','divHideHeaders');
            divHideHeaders.setAttribute('class','divHideHeaders');
            divHideHeaders.innerHTML = 'Hide HP/PP Headers?';
            divHPOptions.insertBefore(divHideHeaders, null);
           
            var chkHideHeaders = document.createElement('input');
            chkHideHeaders.setAttribute('id','chkHideHeaders');
            chkHideHeaders.setAttribute('class','chkHideHeaders');
            chkHideHeaders.setAttribute('type','checkbox');
            chkHideHeaders.checked = TH_PStat_HideHeaders;
            divHideHeaders.insertBefore(chkHideHeaders, divHideHeaders.firstChild);
            chkHideHeaders.addEventListener('click', function(event)
            {
                GM_setValue(TH_PStat_HideHeadersName, chkHideHeaders.checked);
                for (var i = 0; i<parent.frames.length; i++)
                {
                    if(parent.frames[i].name == 'nav')
                    {
                        parent.frames[i].location.reload();
                        break;
                    }
                }
            }, true);
           
            var btnChangeHPColor = document.createElement('input');
            btnChangeHPColor.setAttribute('type','button');
            btnChangeHPColor.setAttribute('id','btnChangeHPColor');
            btnChangeHPColor.setAttribute('class','btnChangeHPColor');
            btnChangeHPColor.value = 'Change HP Color';
            divHPOptions.insertBefore(btnChangeHPColor, null);
            btnChangeHPColor.addEventListener('click', function(e)
            {
                if(btnChangeHPColor.value == 'Close Form')
                {
                    GM_setValue(TH_PStatPanelVisibleName, "none")
                    document.getElementById('divColorHP').style.display = 'none';
                    btnChangeHPColor.value = 'Change HP Color';
                }
                else
                {
                    GM_setValue(TH_PStatPanelVisibleName, "block")
                    createChangeColor("HP");
                    btnChangeHPColor.value = 'Close Form';
                }
            }, true);
           
            divHPOptions.insertBefore(document.createElement('br'), null);
           
            var btnChangePPColor = document.createElement('input');
            btnChangePPColor.setAttribute('type','button');
            btnChangePPColor.setAttribute('id','btnChangePPColor');
            btnChangePPColor.setAttribute('class','btnChangePPColor');
            btnChangePPColor.value = 'Change PP Color';
            divHPOptions.insertBefore(btnChangePPColor, null);
            btnChangePPColor.addEventListener('click', function(e)
            {
                if(btnChangePPColor.value == 'Close Form')
                {
                    GM_setValue(TH_PStatPanelVisibleName, "none")
                    document.getElementById('divColorPP').style.display = 'none';
                    btnChangePPColor.value = 'Change PP Color';
                }
                else
                {
                    GM_setValue(TH_PStatPanelVisibleName, "block")
                    createChangeColor("PP");
                    btnChangePPColor.value = 'Close Form';
                }
            }, true);
           
           
            divHPOptions.insertBefore(document.createElement('br'), null);
            divHPOptions.insertBefore(document.createElement('br'), null);
            divHPOptions.insertBefore(document.createElement('br'), null);
           
            var cssHPOptions = ".divHPOptions" +
                        "{" +
                            "" +
                        "}" +
                        ".imgLoading" +
                        "{" +
                            "display:none;" +
                        "}" +
                        ".aHPUpdates" +
                        "{" +
                            "text-decoration:underline;" +
                            "cursor:pointer;" +
                            "font-size:x-small;" +
                            "color:orange;" +
                        "}" +
                        ".divHideHeaders" +
                        "{" +
                        "}" +
                        ".selHideHeaders" +
                        "{" +
                        "}";
            TH_PStat_AddGlobalStyle(cssHPOptions);
        }
    }
}

function createChangeColor(control)
{
    if(!control){control = "";}
    var divColor = document.getElementById('divColor'+control)
    if(divColor)
    {
        divColor.style.display = 'block';
    }
    else
    {
        divColor = document.createElement('div');
        divColor.setAttribute('id','divColor'+control);
        divColor.setAttribute('class','divColor');
        divHPOptions.insertBefore(divColor, null);
       
        var divColorTitle = document.createElement('span');
        divColorTitle.setAttribute('id','divColorTitle');
        divColorTitle.setAttribute('class','divColorTitle');
        divColor.insertBefore(divColorTitle, divColor.firstChild);

        var spanColorTable = document.createElement('table');
        spanColorTable.setAttribute('id', 'spanColorTable');
        spanColorTable.setAttribute('class', 'spanColorTable');
        spanColorTable.innerHTML = "<tr><td>Change Color - " + control + "</td><td id='tdClose' align='right'></td></tr>";
        divColorTitle.insertBefore(spanColorTable, null);
       
        var divColorTest = document.createElement('div')
        divColorTest.setAttribute('id', 'divColorTest'+control);
        divColorTest.setAttribute('class', 'divColorTest'+control);
        divColorTest.innerHTML = '&nbsp;';
        divColor.insertBefore(divColorTest, null);
       
        var color = GM_getValue('TH_PStat_'+control+'Color',"0,0,0");
        var colors = color.split(",");
       
        var divR = document.createElement('div');
        divR.setAttribute('id', 'divR');
        divR.setAttribute('class', 'divR');
        divR.innerHTML = "All values from 0-255<br>Red Value:";
        divColor.insertBefore(divR, null);
       
        var txtR = document.createElement('input')
        txtR.setAttribute('id', 'txtR');
        txtR.setAttribute('class', 'txtR');
        txtR.setAttribute('type','text');
        txtR.value = colors[0];
        divR.insertBefore(txtR, null);
        txtR.addEventListener('blur',function(e){
            divColorTest.style.backgroundColor = "rgb(" + txtR.value + "," +txtG.value +","+txtB.value+")";
        }, true);
       
        var divG = document.createElement('div');
        divG.setAttribute('id', 'divG');
        divG.setAttribute('class', 'divG');
        divG.innerHTML = "Green Value:";
        divColor.insertBefore(divG, null);
       
        var txtG = document.createElement('input')
        txtG.setAttribute('id', 'txtG');
        txtG.setAttribute('class', 'txtG');
        txtG.setAttribute('type','text');
        txtG.value = colors[1];
        divG.insertBefore(txtG, null);
        txtG.addEventListener('blur',function(e){
            divColorTest.style.backgroundColor = "rgb(" + txtR.value + "," +txtG.value +","+txtB.value+")";
        }, true);
       
        var divB = document.createElement('div');
        divB.setAttribute('id', 'divB');
        divB.setAttribute('class', 'divB');
        divB.innerHTML = "Blue Value:";
        divColor.insertBefore(divB, null);
       
        var txtB = document.createElement('input')
        txtB.setAttribute('id', 'txtB');
        txtB.setAttribute('class', 'txtB');
        txtB.setAttribute('type','text');
        txtB.value = colors[2];
        divB.insertBefore(txtB, null);
        txtB.addEventListener('blur',function(e){
            divColorTest.style.backgroundColor = "rgb(" + txtR.value + "," +txtG.value +","+txtB.value+")";
        }, true);
       
        var divAccept = document.createElement('div')
        divAccept.setAttribute('id', 'divAccept');
        divAccept.setAttribute('class', 'divAccept');
        divColor.insertBefore(divAccept, null);
       
        var divError = document.createElement('div');
        divError.setAttribute('id', 'divError');
        divError.setAttribute('class', 'divError');
        divError.innerHTML = '';
        divAccept.insertBefore(divError, null);
       
        var btnAccept = document.createElement('input');
        btnAccept.setAttribute('type','button');
        btnAccept.value = 'Choose Color';
        divAccept.insertBefore(btnAccept, null);
        btnAccept.addEventListener('click',function(e){
            var errText = "";
           
            if(isNaN(txtR.value) || parseInt(txtR.value) < 0 || parseInt(txtR.value) > 255)
            {
                errText += (errText!=""?"<br>":"") + "Invalid Red Value.  Valid values are in the range 0 to 255";
            }
            if(isNaN(txtG.value) || parseInt(txtG.value) < 0 || parseInt(txtG.value) > 255)
            {
                errText += (errText!=""?"<br>":"") + "Invalid Green Value.  Valid values are in the range 0 to 255";
            }
            if(isNaN(txtB.value) || parseInt(txtB.value) < 0 || parseInt(txtB.value) > 255)
            {
                errText += (errText!=""?"<br>":"") + "Invalid Blue Value.  Valid values are in the range 0 to 255";
            }
           
            if(errText == "")
            {
               
                GM_setValue('TH_PStat_'+control+'Color',txtR.value + "," +txtG.value +","+txtB.value);
                for (var i = 0; i<parent.frames.length; i++)
                {
                    if(parent.frames[i].name == 'nav')
                    {
                        parent.frames[i].location.reload();
                        break;
                    }
                }
                document.getElementById('divColor'+control).style.display = 'none';
                document.getElementById('btnChange'+control+'Color').value = 'Change ' + control + ' Color';
            }
            else
            {
                divError.innerHTML = errText;
            }
        },true)
   
        var cssColor = ".divColor" +
                        "{" +
                            "text-alignment: center;" +
                            "border: 2px outset;" +
                            "-moz-border-radius: 0.5em !important;" +
                            "position: absolute;" +
                            "top: " + (window.innerHeight/2)  + "px;" +
                            "display: " + GM_getValue(TH_PStatPanelVisibleName, "none") + ";"+
                            "left: " + ((window.innerWidth/2)-125)  + "px;" +
                            "background-color: lightgrey;" +
                            "width: 250px;" +
                        "}" +
                        ".divColorTitle" +
                        "{" +
                            "top: 0px;"+
                            "left: 0px;"+
                            "position: relative;"+
                            "width: 9999px;"+
                            "background-color: silver;"+
                        "}"+
                        ".spanColorTable" +
                        "{" +
                            "top: 0px;"+
                            "left: 0px;"+
                            "position: relative;"+
                            "width: 100%;"+
                            "background-color: silver;"+
                        "}" +
                        ".txtR" +
                        "{" +
                            "width:60px;" +
                        "}" +
                        ".txtG" +
                        "{" +
                            "width:60px;" +
                        "}" +
                        ".txtB" +
                        "{" +
                            "width:60px;" +
                        "}" +
                        ".divError" +
                        "{" +
                            "color:red;" +
                        "}" +
                        ".divColorTest"+control +
                        "{" +
                            "position:absolute;" +
                            "top:25px;" +
                            "left:175px;" +
                            "width:50px;" +
                            "height:50px;" +
                            "background-color:rgb("+GM_getValue('TH_PStat_'+control+'Color',"0,0,0")+");" +
                            "border: solid 1px white;" +
                        "}";
        TH_PStat_AddGlobalStyle(cssColor);
    }
}
Leader of PFE league. If you wish to worship me, ask me about joining my secondary league Cult of Satan (the largest league in the game!).
Satan
Posts: 1855
Joined: Mon Nov 19, 2007 6:29 pm
Location: Florida
Contact:

Re: HP/PP greasemonkey script

Post by Satan »

Version of the NL rebuff script that works with or without the HP/PP status bar script

Code: Select all

// ==UserScript==
// @name           NardoLoopa's TH Re-Buff
// @namespace      http://www.ghostmanonfirst.com/
// @include        *.twilightheroes.com/nav.php
// @include        *.twilightheroes.com/skills.php
// @description    Twilight Heroes Re-up Buff from Nav Pane
// @version        0.3.0
// @license        (CC); http://creativecommons.org/licenses/by-nc-sa/3.0/
// @author         NardoLoopa
// @require        http://ajax.googleapis.com/ajax/libs/jquery/1.3/jquery.min.js
//
// ==/UserScript==

/*************************** Description ***************************
 NardoLoopa's TH Re-Buff
 Copyright NardoLoopa 2010

 Adds links to cast buffs from the nav pane.

 If you like this script consider donating Silver Starts to encourage
 the developer.

*******************************************************************/

/*************************** Change Log ***************************
Latest Update:
0.1.0:    Initial release
0.1.1:    Removed skill detection due because of multi-skills.
          Now user responsibility to know which buffs they can re-up.
          This is probably more useful than doing it the other way
          for the time being.
0.1.2:    Refresh pwdhash cookie each time you see the skills page
0.2.0:    added Med-Kit skill to heal HP.  Later I'll add others.
0.3.0:    multi-cast (contribution from TeKRunneR).

*******************************************************************/

var PwdHash       = GM_getValue("PwdHash");
var CharacterName = GM_getValue("CharacterName");
var Skills        = GM_getValue("Skills") ? GM_getValue("Skills").split(";") : null;

// Number of times each link will cast the spell
const NUM_CASTS_1 = 1;
const NUM_CASTS_2 = 2;
const NUM_CASTS_5 = 5;
const HEAL_SKILL  = 104; //First Aid

//looking for the Skills page form cookie to persist for later
//get PwdHash
function getPwdHash () {
   if (document.location.pathname=="/skills.php") {
      var snapHidden = document.evaluate("//input[@name='pwd']",
            document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
      if (!snapHidden.snapshotLength > 0) {
         GM_Log("Couldn't find the cookie on the skills page.");
      }
      else {
         var pwd = snapHidden.snapshotItem(0);
         //GM_log("Setting 'PwdHash' => '" +  pwd.getAttribute('value') + "'");
         GM_setValue("PwdHash", pwd.getAttribute('value'));
         if (!PwdHash) {
            reloadNavFrame();
         }
         PwdHash = pwd.getAttribute('value');
      }
   }
}

//get CharacterName
function getCharacterName () {
   if (document.location.pathname=="/nav.php") {
      var snap = document.evaluate("//a[@href='character.php']",
            document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
      if (!snap.snapshotLength > 0) {
         GM_Log("Couldn't find the character name on the nav page.");
      }
      else {
         var charName = snap.snapshotItem(0); 
         //GM_log("Setting 'CharacterName' => '" +  charName.innerHTML + "'");
         GM_setValue("CharacterName", CharacterName = charName.innerHTML);
      }
   }
}

//get skills you can rebuff
function getCurrentSkills () {
   if (document.location.pathname=="/skills.php") {
      var options = document.evaluate("//option",
            document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);
      if (!options.snapshotLength > 0) {
         GM_Log("Couldn't find any skills on the skills page.");
      }
      else {
         //GM_log("Found " +  options.snapshotLength + " skills on the page");
         Skills = new Array();
         for (var i = 0; i < options.snapshotLength; i++) {
            Skills[i] = options.snapshotItem(i).getAttribute('value');
         }
         GM_setValue("Skills", Skills.join(";"));
      }
  }
}

function reloadNavFrame() {
   document.location.reload();
}

//Call the skill page to re-up the buff
function rebuff (evt, skillNum, numCasts) { 
   if (!PwdHash) {
      alert("Visit the Skillpage first, please.");
      return;
   }
   
   // Store the value
   GM_setValue("valSkill"+skillNum, numCasts);
   //GM_log("Set "+numCasts+" as value valSkill"+skillNum);

   //flash it yellow
   evt.target.parentNode.parentNode.firstChild.innerHTML = "<font color='#FFFF00'>" 
      + evt.target.parentNode.parentNode.firstChild.innerHTML + "</font>";

   GM_xmlhttpRequest({
      method: "POST",
      url: "http://www.twilightheroes.com/skills.php",
      headers: { "Content-type" : "application/x-www-form-urlencoded" },
      data: encodeURI(
         "pwd=" + PwdHash 
         + "&whichskill_cast=" + skillNum
         + "&numtimes=" + numCasts
         + "&bufftarget=" + CharacterName),
      onload: function(e) { processSkillPage(e); },
      onerror: function(e) { alert("Error: " + e.responseText); },
   });
}

//callback for the skillpage
//look for illegal skills and reload the page.
function processSkillPage (e) {
   if (e.responseText.indexOf("You appear to be trying to use a skill you don't have.") > -1) {
      alert ("Nice try; you don't have that skill.");
   }
   reloadNavFrame();
   
}

function incrVal(spValue){
	var currVal = parseInt(spValue.innerText);
	//GM_log("currVal = "+currVal);
	currVal++;
	//GM_log("newVal = "+currVal);
	spValue.innerText = spValue.textContent = currVal;
}

function decrVal(spValue){
	var currVal = parseInt(spValue.innerText);
	//GM_log("currVal = "+currVal);
	if(currVal > 1) { currVal--; }
	//GM_log("newVal = "+currVal);
	spValue.innerText = spValue.textContent = currVal;
}

//add buff up arrow and action
function addBuffUp (itemElement, skillNum, effectName, duration) {
   //GM_log("skill: [" + skillNum + "] for [" + effectName + "] [" + duration + "]");
   var putPlusFirst = 0;
   if (itemElement.nodeName == "DIV") { itemElement.style.display = "inline"; }

   itemElement.innerHTML += ' ';
   
   var spGroup = document.createElement('span');
   //spGroup.id = skillNum;

   $(spGroup).hover(
      function (e) { $(this).children(':last').show();},
      function (e) { $(this).children(':last').hide();}
      );

   var spGo = document.createElement('span');
   var spSub = document.createElement('span');
   var spMinus = document.createElement('span');
   var spValue = document.createElement('span');
   var spPlus = document.createElement('span');
   
   spGo.innerText = spGo.textContent = "\u21e7";

   spMinus.innerText = spMinus.textContent = '-';
   spPlus.innerText = spPlus.textContent = '+';
   
   // Check if we know the value to display, otherwise display 1
   var valSkill = GM_getValue("valSkill"+skillNum);
   if (valSkill == null){
	   spValue.innerText = spValue.textContent = '1';
   } else {
      spValue.innerText = spValue.textContent = valSkill;	
   }
   
   spMinus.addEventListener('click', function handler (evt) { decrVal(spValue); }, false);
   spPlus.addEventListener('click', function handler (evt) { incrVal(spValue); }, false);
   
   spGroup.appendChild(spGo);
   spGroup.appendChild(spSub);
   spSub.appendChild(spMinus);
   spSub.appendChild(spValue);
   spSub.appendChild(spPlus);

   spSub.style.border="1px solid white";

   itemElement.parentNode.insertBefore(spGroup, itemElement.nextSibling);
   
   spMinus.style.paddingLeft="3px";
   spMinus.style.paddingRight="1px";
   
   spValue.style.paddingLeft="1px";
   spValue.style.paddingRight="1px";
   
   spPlus.style.paddingLeft="1px";
   spPlus.style.paddingRight="3px";
   
   spSub.style.marginRight="3px";
   
   spMinus.style.cursor="pointer";
   spPlus.style.cursor="pointer";
   spGo.style.cursor="pointer";
   
   
   spSub.style.display="none";

   spGo.addEventListener('click', function handler (evt) { 
      rebuff(evt, skillNum, spValue.innerText); }
      , false);
}

//main/////////////////////////////////////////////////////////////////////////
getPwdHash();
getCharacterName();
getCurrentSkills();

//Process the nav page to spruce it up with rebuff decorations
if (document.location.pathname=="/nav.php") {

   //addHP + up
   var hpEl = document.getElementById("tblHPTotal");
   var div = document.createElement("div");
   div.style.display="inline";
   if (!hpEl) hpEl = document.getElementById("hpstring");
   hpEl.parentNode.replaceChild(div, hpEl);
   div.appendChild(hpEl);
   addBuffUp(hpEl, HEAL_SKILL, "First Aid", 0);

   //add Active effects + up
   //GM_log("Got 'PwdHash' => '" + PwdHash + "'");
   var curDivElement;
   var allDivs = document.evaluate(
      '//div[@onclick]',
      document, null, XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, null);

   for (var i = 0; i < allDivs.snapshotLength; i++) {
      curDivElement = allDivs.snapshotItem(i);
      //GM_log("Skills: " + Skills.join(":"));

      if ((curDivElement.innerHTML.indexOf("min") != -1)) { 
	      var effectName = curDivElement.innerHTML.substring(0,curDivElement.innerHTML.indexOf("-")-1); 
	      var duration = curDivElement.innerHTML.substring(curDivElement.innerHTML.indexOf(">")+1,curDivElement.innerHTML.indexOf(" min")); 
	      var str = curDivElement.getAttribute("onclick");
	      var skillNum = str.substring(str.indexOf("(")+1,str.indexOf(")")); 
         //if (Skills.indexOf(skillNum) != -1) {
	         addBuffUp(curDivElement, skillNum, effectName, duration);
         //}
      } 
   }
}
Leader of PFE league. If you wish to worship me, ask me about joining my secondary league Cult of Satan (the largest league in the game!).
Muhandes
Posts: 732
Joined: Mon Nov 03, 2008 12:54 am
Contact:

Re: HP/PP greasemonkey script

Post by Muhandes »

well done, I'm also happy to see my chips again (never really used the rebuff script so can't say how well it works)
Post Reply

Who is online

Users browsing this forum: No registered users and 14 guests