Light Rising Remember Last Weapon

Remembers last weapon used and autoselects it.

  1. // ==UserScript==
  2. // @name Light Rising Remember Last Weapon
  3. // @namespace http://userscripts.org/users/125692
  4. // @description Remembers last weapon used and autoselects it.
  5. // @include *lightrising.com*game.cgi
  6. // @version 0.0.1.20140406170308
  7. // ==/UserScript==
  8.  
  9. (function() {
  10.  
  11.  
  12. //select any remembered weapon
  13. var gab=document.getElementsByClassName("gamebox actionbox")[0];
  14. var attackbuttons=document.evaluate(
  15. ".//input[@value='Attack']",//it might need the leading '.'
  16. gab, //as it is limited to gab
  17. null,
  18. XPathResult.ORDERED_NODE_SNAPSHOT_TYPE,
  19. null);//look for attack button
  20.  
  21. if(attackbuttons.snapshotLength>0){
  22. var attackbutton=attackbuttons.snapshotItem(0);//first input named attack
  23. attackbutton.id='AttackButton';
  24. var dropdowns=attackbutton.parentNode.getElementsByTagName('select');
  25. var dropdownwewant=dropdowns[1];
  26. var dropdownoptions=dropdownwewant.getElementsByTagName('option')
  27. var weaponvalue=GM_getValue('GMweaponvalue',-1);
  28. var keeper=0;
  29. if (weaponvalue>0){//we have a weapon value. lets try and select it.
  30. for (i=0;i<dropdownoptions.length;i++ ){
  31. test=dropdownoptions[i].value;
  32. if (test==weaponvalue){
  33. keeper=i;
  34. break;//stop looking
  35. }
  36. }
  37. dropdownwewant.selectedIndex=keeper;
  38. }
  39. }
  40.  
  41. //event fuction to be fire upon clicking attack button
  42. var storeattack=function(e) {
  43. var attackform=e.target.parentNode;
  44. var dropdowns=attackform.getElementsByTagName('select');
  45. var dropdownwewant=dropdowns[1];
  46. GM_setValue('GMweaponvalue',dropdownwewant[dropdownwewant.selectedIndex].value)
  47. }
  48.  
  49. //setup event
  50. if(document.getElementById('AttackButton')){
  51. document.getElementById('AttackButton').addEventListener("click",storeattack,true);
  52. }
  53.  
  54. //EOF
  55. })();