Neopets Lottery Autobuyer

Autobuys 20 random lottery ticket links on neopets

  1. // ==UserScript==
  2. // @name Neopets Lottery Autobuyer
  3. // @namespace shiftasterisk
  4. // @version 0.4
  5. // @description Autobuys 20 random lottery ticket links on neopets
  6. // @author shiftasterisk
  7. // @match http://www.neopets.com/games/lottery.phtml
  8. // @include https://code.jquery.com/jquery-3.1.1.min.js
  9. // @grant none
  10. // ==/UserScript==
  11. $('input[type="submit"][value="Buy a Lottery Ticket!"]').parent().append("<input id='buyTwenty' type='button' value='Buy 20 Quick Picks'>");
  12. $('input[type="submit"][value="Buy a Lottery Ticket!"]').parent().parent().parent().append("<div id='linkContainer'></div>");
  13.  
  14. var numberOfTickets = 20;
  15. var tickets = [];
  16.  
  17. $('#buyTwenty').click(function() {
  18. alert("Auto buying tickets, just wait for the page to refresh (about 20 seconds)");
  19. tickets = [];
  20. $("#linkContainer").empty();
  21. selectTickets();
  22. buyTickets();
  23. });
  24.  
  25. function buyTickets() {
  26. for (x = 0; x < tickets.length; x++) {
  27. url = 'http://www.neopets.com/games/process_lottery.phtml?one=' + tickets[x][0] + '&two=' + tickets[x][1] + '&three=' + tickets[x][2] + '&four=' + tickets[x][3] + '&five=' + tickets[x][4] + '&six=' + tickets[x][5];
  28. $(document).queue('tickets', createTicket(url));
  29. }
  30.  
  31. $(document).queue('tickets', function() {
  32. console.log("finished buying tickets");
  33. location.reload();
  34. });
  35.  
  36. $(document).dequeue('tickets');
  37. }
  38.  
  39. function createTicket(ticket) {
  40. return function(next) {
  41. buyTicket(ticket, next);
  42. };
  43. }
  44.  
  45. function buyTicket(ticket, next) {
  46. setTimeout(function() {
  47. $.ajax({
  48. url: ticket,
  49. async: false,
  50. success: function(result) {
  51. console.log("bought ticket");
  52. }
  53. });
  54. next();
  55. }, 1000);
  56. }
  57.  
  58. function selectTickets() {
  59. var ticketsAdded = 0;
  60. while (ticketsAdded < numberOfTickets) {
  61. currentTicket = [];
  62. for (y = 0; y < 6; y++) {
  63. currentTicket = addNumberToTicket(currentTicket);
  64. }
  65. if (!isDuplicateTicket(currentTicket)) {
  66. tickets.push(currentTicket);
  67. ticketsAdded++;
  68. console.log("totalTickets - " + ticketsAdded);
  69. } else {
  70. currentTicket = [];
  71. }
  72. }
  73. }
  74.  
  75. function addNumberToTicket(currentTicket) {
  76. var lotteryNumber = Math.round(Math.random() * 29) + 1;
  77. console.log(currentTicket);
  78. console.log(lotteryNumber);
  79. if (currentTicket.includes(lotteryNumber)) {
  80. console.log("duplicate number - going in again");
  81. currentTicket = addNumberToTicket(currentTicket);
  82. } else {
  83. currentTicket.push(lotteryNumber);
  84. }
  85. return currentTicket;
  86. }
  87.  
  88. function isDuplicateTicket(currentTicket) {
  89. for (x = 0; x < tickets.length; x++) {
  90. if (JSON.stringify(currentTicket.sort()) === JSON.stringify(tickets[x].sort())) {
  91. console.log("duplicate ticket");
  92. return true;
  93. }
  94. }
  95. return false;
  96. }