Advertisement
Guest User

Untitled

a guest
Feb 21st, 2016
320
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.05 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. var spiritHeal = getHealForPotion("Spirit Healing Potion");
  38.  
  39. //
  40. // Get weakest potion that will give full heal
  41. //
  42. if (weakHeal >= healthLost) { bestPotion = findLinkContainingString("Weak Healing Potion"); }
  43. if (standardHeal >= healthLost) { bestPotion = findLinkContainingString("Standard Healing Potion"); }
  44. if (strongHeal >= healthLost) { bestPotion = findLinkContainingString("Strong Healing Potion"); }
  45. if (greatHeal >= healthLost) { bestPotion = findLinkContainingString("Greater Healing Potion"); }
  46. if (superiorHeal >= healthLost) { bestPotion = findLinkContainingString("Superior Healing Potion"); }
  47. if (spiritHeal >= healthLost) { bestPotion = findLinkContainingString("Spirit Healing Potion"); }
  48.  
  49. //
  50. // If no potion gives full heal, find strongest in stock.
  51. //
  52. if (bestPotion == null) {
  53. if (spiritHeal > 0) { bestPotion = findLinkContainingString("Spirit Healing Potion"); }
  54. else if (superiorHeal > 0) { bestPotion = findLinkContainingString("Superior Healing Potion"); }
  55. else if (greatHeal > 0) { bestPotion = findLinkContainingString("Greater Healing Potion"); }
  56. else if (strongHeal > 0) { bestPotion = findLinkContainingString("Strong Healing Potion"); }
  57. else if (standardHeal > 0) { bestPotion = findLinkContainingString("Standard Healing Potion"); }
  58. else if (weakHeal > 0) { bestPotion = findLinkContainingString("Weak Healing Potion"); }
  59. }
  60. return bestPotion;
  61. }
  62.  
  63. var neoquest=document.body.innerHTML.split('NeoQuest is brought to you by')[1];
  64. var healthString = neoquest.split('Health: ')[1].split(" ")[0].replace(/<[\/]{0,1}(b|B)[^><]*>/g,"");
  65. var health = eval(healthString);
  66. var healthLost = parseInt(healthString.split("/")[1]) - parseInt(healthString.split("/")[0])
  67.  
  68. if(neoquest.search('to see what you found')!=-1){
  69. location.href='http://www.neopets.com/games/neoquest/neoquest.phtml';
  70. }
  71. for(i=0;i<document.forms.length;i++){
  72. if(document.forms[i].elements[0].value=="Click here to return to the map"){
  73. document.forms[i].submit();
  74. }
  75. }
  76.  
  77. if(neoquest.search('navarrows.gif')!=-1){
  78. location.href='http://www.neopets.com/games/neoquest/neoquest.phtml?action=move&movedir=';
  79. }
  80. if(neoquest.search('to begin the fight')!=-1){
  81. location.href='http://www.neopets.com/games/neoquest/neoquest.phtml';
  82. }
  83.  
  84. //
  85. // We need to heal
  86. //
  87. if(health<(0.5)&&((neoquest.search('Spirit of Growth')!=-1)||(neoquest.search('Healing Potion')!=-1))){
  88. if(neoquest.search('Spirit of Growth')!=-1){
  89. findLinkContainingString("Spirit of Growth").click();
  90.  
  91. }else if(neoquest.search('Healing Potion')!=-1){
  92. findBestPotion().click();
  93. }
  94.  
  95. //
  96. // Attack
  97. //
  98. } else if(neoquest.search('Attack')!=-1){
  99. findLinkContainingString("Attack").click();
  100.  
  101. } else if(neoquest.search('Do nothing')!=-1){
  102. findLinkContainingString("Do nothing").click();
  103. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement