w35l3y

Test : Food Club

Apr 13th, 2016
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // ==UserScript==
  2. // @name           Test : Food Club
  3. // @namespace      http://gm.wesley.eti.br
  4. // @author         w35l3y
  5. // @email          [email protected]
  6. // @copyright      2016+, w35l3y (http://gm.wesley.eti.br)
  7. // @license        GNU GPL
  8. // @homepage       http://gm.wesley.eti.br
  9. // @version        1.0.0
  10. // @language       en
  11. // @include        http://www.neopets.com/pirates/foodclub.phtml?type=bet
  12. // @grant          GM_getValue
  13. // @grant          GM_setValue
  14. // @grant          GM_xmlhttpRequest
  15. // @grant          GM_getResourceText
  16. // @resource       foodclubJson https://gist.github.com/w35l3y/fab231758eb0991f36a0/raw/foodclub.json
  17. // @require        https://github.com/w35l3y/localStorageDB/raw/master/localstoragedb.js
  18. // @require        https://github.com/w35l3y/userscripts/raw/master/includes/Includes_XPath/63808.user.js
  19. // @require        https://github.com/w35l3y/userscripts/raw/master/includes/Includes_HttpRequest/56489.user.js
  20. // @require        https://github.com/w35l3y/userscripts/raw/master/includes/Includes_Neopets_%5BBETA%5D/main.user.js
  21. // @require        https://github.com/w35l3y/userscripts/raw/master/scripts/../../../raw/master/includes/Includes_Neopets_FoodClub/main.user.js?1
  22. // ==/UserScript==
  23.  
  24. var np = new Neopets(document),
  25. fc = new FoodClub(np);
  26.  
  27. fc.odds(function (o) {  // could be replaced by fc.parse("bet") once the @include is the same of what fc.odds(cb) does
  28.     var r = o.response;
  29.     if (r.max_bet) {    // check whether the food club is open
  30.         fc.get(function (o) {   // retrieve the bets of a custom page
  31.             (function recursive (list) {    // recursively iterate through the list of bets
  32.                 if (list.length) {
  33.                     var bet = list[0];
  34.                     list.shift();
  35.  
  36.                     if (confirm("Place a bet?\n\n" + r.max_bet + " NP\t" + bet.odds + ":1\t" + (r.max_bet * bet.odds) + " NP\n\n" + bet.arenas.map(function (b) {
  37.                         return b.name + "\t" + b.pirate.name;
  38.                     }).join("\n"))) {   // confirm the current bet
  39.                         try {
  40.                             fc.bet(function (o) {
  41.                                 console.log(o);
  42.                                 recursive(list);
  43.                             }, {
  44.                                 check   : r.arenas, // check whether the bets are possible
  45.                                 value   : r.max_bet,    // value of the bets
  46.                                 arenas  : bet.arenas,   // bets (may contain informations about arena, pirate and odds)
  47.                                 odds    : bet.odds, // odds - optional
  48.                             });
  49.                         } catch (e) {
  50.                             recursive(list);
  51.                         }
  52.                     } else {
  53.                         recursive(list);
  54.                     }
  55.                 } else {
  56.                     alert("Complete");
  57.                 }
  58.             }(o.response.list.sort(function (a, b) {    // sort and filter the list of bets
  59.                 if (a.round == b.round) {
  60.                     return 0;
  61.                 }
  62.  
  63.                 return (a.round > b.round?-1:1);
  64.             }).slice(0, 10)));
  65.         }, {
  66.             url : "http://www.neopets.com/~nopunchameplz"   // page containing the bets
  67.         });
  68.     }
  69. });
Advertisement
Add Comment
Please, Sign In to add comment