Advertisement
Guest User

NeoQuest 1 Attacker

a guest
Mar 18th, 2016
248
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.79 KB | None | 0 0
  1. // ==UserScript==
  2. // @name Neoquest Attacker
  3. // @namespace http://userscripts.org/users/useridnumber
  4. // @include http://www.neopets.com/games/neoquest/*
  5. // ==/UserScript==
  6.  
  7. function findLinkContainingString(myStr) {
  8. var aTags = document.getElementsByTagName("a");
  9. var searchText = myStr;
  10. var found;
  11.  
  12. for (var i = 0; i < aTags.length; i++) {
  13. if (aTags[i].textContent.search(searchText) != -1) {
  14. console.log("Found tag with textContent: " + aTags[i].textContent);
  15. found = aTags[i];
  16. break;
  17. }
  18. }
  19. return found;
  20. }
  21.  
  22. function getHealForPotion(potion) {
  23. var link = findLinkContainingString(potion);
  24. if (link == null) {
  25. return 0;
  26. }
  27. return parseInt(link.textContent.match(/(\d+)/)[0])
  28. }
  29.  
  30. function findBestPotion() {
  31. var bestPotion;
  32. var weakHeal = getHealForPotion("Weak Healing Potion");
  33. var standardHeal = getHealForPotion("Standard Healing Potion");
  34. var strongHeal = getHealForPotion("Strong Healing Potion");
  35. var greatHeal = getHealForPotion("Greater Healing Potion");
  36. var superiorHeal = getHealForPotion("Superior Healing Potion");
  37.  
  38. //
  39. // Get weakest potion that will give full heal
  40. //
  41. if (weakHeal >= healthLost) { bestPotion = findLinkContainingString("Weak Healing Potion"); }
  42. if (standardHeal >= healthLost) { bestPotion = findLinkContainingString("Standard Healing Potion"); }
  43. if (strongHeal >= healthLost) { bestPotion = findLinkContainingString("Strong Healing Potion"); }
  44. if (greatHeal >= healthLost) { bestPotion = findLinkContainingString("Greater Healing Potion"); }
  45. if (superiorHeal >= healthLost) { bestPotion = findLinkContainingString("Superior Healing Potion"); }
  46.  
  47. //
  48. // If no potion gives full heal, find strongest in stock.
  49. //
  50. if (bestPotion == null) {
  51. if (superiorHeal > 0) { bestPotion = findLinkContainingString("Superior Healing Potion"); }
  52. else if (greatHeal > 0) { bestPotion = findLinkContainingString("Greater Healing Potion"); }
  53. else if (strongHeal > 0) { bestPotion = findLinkContainingString("Strong Healing Potion"); }
  54. else if (standardHeal > 0) { bestPotion = findLinkContainingString("Standard Healing Potion"); }
  55. else if (weakHeal > 0) { bestPotion = findLinkContainingString("Weak Healing Potion"); }
  56. }
  57. return bestPotion;
  58. }
  59.  
  60. var neoquest=document.body.innerHTML.split('NeoQuest is brought to you by')[1];
  61. var healthString = neoquest.split('Health: ')[1].split(" ")[0].replace(/<[\/]{0,1}(b|B)[^><]*>/g,"");
  62. var health = eval(healthString);
  63. var healthLost = parseInt(healthString.split("/")[1]) - parseInt(healthString.split("/")[0])
  64.  
  65. if(neoquest.search('to see what you found')!=-1){
  66. location.href='http://www.neopets.com/games/neoquest/neoquest.phtml';
  67. }
  68. for(i=0;i<document.forms.length;i++){
  69. if(document.forms[i].elements[0].value=="Click here to return to the map"){
  70. document.forms[i].submit();
  71. }
  72. }
  73.  
  74. if(neoquest.search('navarrows.gif')!=-1){
  75. location.href='http://www.neopets.com/games/neoquest/neoquest.phtml?action=move&movedir=';
  76. }
  77. if(neoquest.search('to begin the fight')!=-1){
  78. location.href='http://www.neopets.com/games/neoquest/neoquest.phtml';
  79. }
  80.  
  81. //
  82. // We need to heal
  83. //
  84. if(health<(0.5)&&((neoquest.search('Spirit of Growth')!=-1)||(neoquest.search('Healing Potion')!=-1))){
  85. if(neoquest.search('Spirit of Growth')!=-1){
  86. findLinkContainingString("Spirit of Growth").click();
  87.  
  88. }else if(neoquest.search('Healing Potion')!=-1){
  89. findBestPotion().click();
  90. }
  91.  
  92. //
  93. // Attack
  94. //
  95. } else if(neoquest.search('Attack')!=-1){
  96. findLinkContainingString("Attack").click();
  97.  
  98. } else if(neoquest.search('Do nothing')!=-1){
  99. findLinkContainingString("Do nothing").click();
  100. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement