Light Rising Remember Last Weapon

Remembers last weapon used and autoselects it.

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 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
})();