Guest User

Grumpy and Wise Kings

a guest
Mar 21st, 2016
261
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name Grumpy and Wise Kings
  3. // @version 0.1
  4. // @match http://www.neopets.com/medieval/grumpyking.phtml
  5. // @match http://www.neopets.com/medieval/wiseking.phtml
  6. // @grant none
  7. // ==/UserScript==
  8. /* jshint -W097 */
  9. 'use strict';
  10.  
  11. var selectors = document.getElementsByTagName("select");
  12.  
  13. // Get Random Integer from min (inclusive) to max (exclusive)
  14. function getRandomInt(min, max) {
  15. return Math.floor(Math.random() * (max - min)) + min;
  16. }
  17.  
  18. // Assign a random selection for the select element at the given index of 'selectors'
  19. function setRandomSelectionForSelector(index) {
  20. selectors[index].selectedIndex = getRandomInt(1, selectors[index].options.length);
  21. }
  22.  
  23. var url = document.location.href;
  24. var isGrumpyOldKing = url.search("grumpy") > 0;
  25. if (isGrumpyOldKing) {
  26. //
  27. // Grumpy Old King
  28. //
  29.  
  30. // What do you do if fierce Peophins has eaten too much tin of olives?
  31. selectors[0].selectedIndex = 3;
  32. selectors[1].selectedIndex = 8;
  33. selectors[2].selectedIndex = 6;
  34. selectors[3].selectedIndex = 1;
  35. selectors[4].selectedIndex = 39;
  36. selectors[5].selectedIndex = 118;
  37. selectors[6].selectedIndex = 1;
  38. selectors[7].selectedIndex = 32;
  39. selectors[8].selectedIndex = 1;
  40. selectors[9].selectedIndex = 143;
  41.  
  42. // Answer: always something random
  43. setRandomSelectionForSelector(10);
  44. setRandomSelectionForSelector(11);
  45. setRandomSelectionForSelector(12);
  46. setRandomSelectionForSelector(13);
  47. setRandomSelectionForSelector(14);
  48. setRandomSelectionForSelector(15);
  49. setRandomSelectionForSelector(16);
  50. setRandomSelectionForSelector(17);
  51.  
  52. } else {
  53. //
  54. // Wise King
  55. //
  56. setRandomSelectionForSelector(0);
  57. setRandomSelectionForSelector(1);
  58. setRandomSelectionForSelector(2);
  59. setRandomSelectionForSelector(3);
  60. setRandomSelectionForSelector(4);
  61. setRandomSelectionForSelector(5);
  62. setRandomSelectionForSelector(6);
  63. setRandomSelectionForSelector(7);
  64. }
RAW Paste Data