Light Rising Remember Last Weapon

Remembers last weapon used and autoselects it.

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 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.

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

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           Light Rising Remember Last Weapon
// @namespace      http://userscripts.org/users/125692
// @description    Remembers last weapon used and autoselects it.
// @include        *lightrising.com*game.cgi
// @version 0.0.1.20140406170308
// ==/UserScript==

(function() {


//select any remembered weapon
var gab=document.getElementsByClassName("gamebox actionbox")[0];
var attackbuttons=document.evaluate(
                    ".//input[@value='Attack']",//it might need the leading '.'
                    gab,                        //as it is limited to gab
                    null,
                    XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
                    null);//look for attack button

if(attackbuttons.snapshotLength>0){
    var attackbutton=attackbuttons.snapshotItem(0);//first input named attack
    attackbutton.id='AttackButton';
    var dropdowns=attackbutton.parentNode.getElementsByTagName('select');
    var dropdownwewant=dropdowns[1];
    var dropdownoptions=dropdownwewant.getElementsByTagName('option')
    var weaponvalue=GM_getValue('GMweaponvalue',-1);
    var keeper=0;
    if (weaponvalue>0){//we have a weapon value. lets try and select it.
        for (i=0;i<dropdownoptions.length;i++ ){
            test=dropdownoptions[i].value;
            if (test==weaponvalue){
                keeper=i;
                break;//stop looking
            }
        }
        dropdownwewant.selectedIndex=keeper;
    }
}

//event fuction to be fire upon clicking attack button
var storeattack=function(e) {
    var attackform=e.target.parentNode;
    var dropdowns=attackform.getElementsByTagName('select');
    var dropdownwewant=dropdowns[1];
    GM_setValue('GMweaponvalue',dropdownwewant[dropdownwewant.selectedIndex].value)
}

//setup event
if(document.getElementById('AttackButton')){
    document.getElementById('AttackButton').addEventListener("click",storeattack,true);
}

//EOF
})();