Light Rising Remember Last Weapon

Remembers last weapon used and autoselects it.

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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