Light Rising Remember Last Weapon

Remembers last weapon used and autoselects it.

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Greasemonkey lub Violentmonkey.

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

Aby zainstalować ten skrypt, wymagana jest instalacje jednego z następujących rozszerzeń: Tampermonkey, Violentmonkey.

Aby zainstalować ten skrypt, wymagana będzie instalacja rozszerzenia Tampermonkey lub Userscripts.

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

Aby zainstalować ten skrypt, musisz zainstalować rozszerzenie menedżera skryptów użytkownika.

(Mam już menedżera skryptów użytkownika, pozwól mi to zainstalować!)

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.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Będziesz musiał zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

Musisz zainstalować rozszerzenie menedżera stylów użytkownika, aby zainstalować ten styl.

(Mam już menedżera stylów użytkownika, pozwól mi to zainstalować!)

// ==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
})();