(Sandboxed) Lioden Improvements

Adds various improvements to the game Lioden. Sandboxed portion of the script.

目前为 2015-10-02 提交的版本。查看 最新版本

  1. // Generated by CoffeeScript 1.9.3
  2.  
  3. /* UserScript options {{{1
  4. See http://wiki.greasespot.net/Metadata_Block for more info.
  5.  
  6. // ==UserScript==
  7. // @name (Sandboxed) Lioden Improvements
  8. // @description Adds various improvements to the game Lioden. Sandboxed portion of the script.
  9. // @namespace ahto
  10. // @version 5.1
  11. // @include http://*.lioden.com/*
  12. // @include http://lioden.com/*
  13. // @require https://greasyfork.org/scripts/10922-ahto-library/code/Ahto%20Library.js?version=75750
  14. // @grant GM_addStyle
  15. // ==/UserScript==
  16. */
  17.  
  18. /* Features and changes {{{1
  19. General:
  20. - Made the second-to-top bar a little slimmer.
  21. - Added significantly more quickly-accessible links, and made the site overall faster and easier to use.
  22.  
  23. Hunting:
  24. - Automatically reloads and flashes the tab when your hunt is finished.
  25.  
  26. Den:
  27. - Can automatically play with all lionesses.
  28. */
  29. var HUMAN_TIMEOUT_MAX, HUMAN_TIMEOUT_MIN, HUNT_BLINK_TIMEOUT, LionPlayer, blinker, getResults, lionPlayer, logout, minutesLeft, moveToToplinks, navbar, newDropdown, newNavbarItem, setHumanTimeout, toplinks, wait,
  30. slice = [].slice;
  31.  
  32. HUNT_BLINK_TIMEOUT = 500;
  33.  
  34. HUMAN_TIMEOUT_MIN = 200;
  35.  
  36. HUMAN_TIMEOUT_MAX = 1000;
  37.  
  38. GM_addStyle("/* Make the top bar slimmer. */\n.main { margin-top: 10px; }\n\n/*\n * Remove the Lioden logo since I can't figure out how to shrink it,\n * and it's taking up too much space on the page. It overlaps the veeery\n * top bar, with the link to the wiki and forums and stuff.\n *\n * TODO: Figure out how to just shrink it instead of flat-out removing it.\n */\n.navbar-brand > img { display: none; }");
  39.  
  40. setHumanTimeout = function(f) {
  41. return setTimeout_(randInt(HUMAN_TIMEOUT_MIN, HUMAN_TIMEOUT_MAX), f);
  42. };
  43.  
  44. navbar = $('.nav.visible-lg');
  45.  
  46. toplinks = $('.toplinks');
  47.  
  48. logout = toplinks.find('a[href="/logout.php"]');
  49.  
  50. moveToToplinks = function(page, linkText) {
  51. var link;
  52. link = navbar.find("a[href='" + page + "']").parent();
  53. link.remove();
  54. link.find('a').text(linkText);
  55. return logout.before(link);
  56. };
  57.  
  58. moveToToplinks('/oasis.php', 'Oasis');
  59.  
  60. moveToToplinks('/boards.php', 'Chatter');
  61.  
  62. moveToToplinks('/news.php', 'News');
  63.  
  64. moveToToplinks('/event.php', 'Event');
  65.  
  66. moveToToplinks('/faq.php', 'FAQ');
  67.  
  68. GM_addStyle("ul li ul.dropdown {\n min-width: 125px;\n background: " + ($('.navbar.navbar-default').css('background')) + ";\n padding-left: 10px;\n padding-bottom: 5px;\n\n display: none;\n position: absolute;\n z-index: 999;\n left: 0;\n}\n\nul li ul.dropdown li {\n display: block;\n}\n\n/* Display the dropdown on hover. */\nul li:hover ul.dropdown {\n display: block;\n}");
  69.  
  70. newDropdown = function(menuItem, dropdownLinks) {
  71. var dropdown, j, len, link, linkText, ref, results;
  72. if (typeof menuItem === 'string') {
  73. menuItem = navbar.find("a[href='" + menuItem + "']").parent();
  74. }
  75. dropdown = $("<ul class=dropdown></ul>");
  76. menuItem.append(dropdown);
  77. results = [];
  78. for (j = 0, len = dropdownLinks.length; j < len; j++) {
  79. ref = dropdownLinks[j], link = ref[0], linkText = ref[1];
  80. results.push(dropdown.append("<li><a href='" + link + "'>" + linkText + "</a></li>"));
  81. }
  82. return results;
  83. };
  84.  
  85. newNavbarItem = function(page, linkText, dropdownLinks) {
  86. var navbarItem;
  87. navbarItem = $("<li><a href='" + page + "'>" + linkText + "</a></li>");
  88. navbar.append(navbarItem);
  89. if (dropdownLinks != null) {
  90. return newDropdown(navbarItem, dropdownLinks);
  91. }
  92. };
  93.  
  94. newDropdown('/hoard.php', [['/hoard.php?type=Food', 'Food'], ['/hoard.php?type=Amusement', 'Amusement'], ['/hoard.php?type=Decoration', 'Decoration'], ['/hoard.php?type=Background', 'Background'], ['/hoard.php?type=Other', 'Other'], ['/hoard.php?type=Buried', 'Buried'], ['/hoard.php?type=Bundles', 'Bundles'], ['/hoard-organisation.php', 'Organisation']]);
  95.  
  96. newDropdown('/explore.php', [['/search.php', 'Search'], ['/trading_center.php', 'Trading Center'], ['/questing.php', 'Quests'], ['/monkeybusiness.php', 'Monkey Shop'], ['/sharpen_claws.php', 'Sharpen Claws'], ['/games.php', 'Games'], ['/patrol.php', 'Patrol'], ['/leaders.php', 'Leaderboards'], ['/special.php', 'Special Lioness']]);
  97.  
  98. newNavbarItem('/hunting.php', 'Hunting');
  99.  
  100. newNavbarItem('/exploring.php', 'Exploring', [['/explorearea.php?id=1', '(1) Temperate S'], ['/explorearea.php?id=2', '(2-5) Shrubland'], ['/explorearea.php?id=3', '(6-10) Trpcl Forest'], ['/explorearea.php?id=4', '(11-15) Dry S'], ['/explorearea.php?id=5', '(16-20) Rocky Hills'], ['/explorearea.php?id=6', '(26-30) Marshl.'], ['/explorearea.php?id=7', '(31+) Waterhole']]);
  101.  
  102. newNavbarItem('/branch.php', 'Branches', [['/branch.php', 'My Branch'], ['/search_branches.php', 'Search']]);
  103.  
  104. newNavbarItem('/territory_map.php', 'Territories');
  105.  
  106. newNavbarItem('/scryingstone.php', 'Scrying Stone', [['/wardrobe.php', 'Wardrobe'], ['/falcons-eye.php', "Falcon's Eye"]]);
  107.  
  108. if (urlMatches(new RegExp('/hunting\\.php', 'i'))) {
  109. minutesLeft = findMatches('div.center > p', 0, 1).text();
  110. getResults = findMatches('input[name=get_results', 0, 1);
  111. if (minutesLeft.length) {
  112. minutesLeft = (/([0-9]+) minutes/.exec(minutesLeft))[1];
  113. minutesLeft = safeParseInt(minutesLeft);
  114. console.log(minutesLeft, 'minutes remaining.');
  115. wait = (minutesLeft + 1) * 60 * 1000;
  116. console.log("Reloading in " + wait + " ms...");
  117. setTimeout_(wait, function() {
  118. return location.reload();
  119. });
  120. } else if (getResults.length) {
  121. blinker = setInterval((function() {
  122. if (document.title === 'Ready!') {
  123. return document.title = '!!!!!!!!!!!!!!!!';
  124. } else {
  125. return document.title = 'Ready!';
  126. }
  127. }), HUNT_BLINK_TIMEOUT);
  128. window.onfocus = function() {
  129. clearInterval(blinker);
  130. return document.title = 'Ready!';
  131. };
  132. }
  133. }
  134.  
  135. if (urlMatches(new RegExp('/territory\\.php', 'i'))) {
  136. LionPlayer = (function() {
  137. LionPlayer.prototype.LION_URL_TO_ID = new RegExp('/lion\\.php.*[?&]id=([0-9]+)');
  138.  
  139. function LionPlayer(autoPlayLink) {
  140. this.autoPlayLink = autoPlayLink;
  141. this.lionIDs = [];
  142. this.safeToClick = true;
  143. this.autoPlayLink.click((function(_this) {
  144. return function() {
  145. return _this.clickListener();
  146. };
  147. })(this));
  148. }
  149.  
  150. LionPlayer.prototype.clickListener = function() {
  151. if (this.safeToClick) {
  152. this.safeToClick = false;
  153. this.updateLionIDs();
  154. return this.play();
  155. }
  156. };
  157.  
  158. LionPlayer.prototype.getLionID = function(lionLink) {
  159. var id, url;
  160. url = lionLink.attr('href');
  161. id = this.LION_URL_TO_ID.exec(url)[1];
  162. return id;
  163. };
  164.  
  165. LionPlayer.prototype.updateLionIDs = function() {
  166. var i, lionLinks;
  167. lionLinks = $('a[href^="/lion.php?id="]');
  168. return this.lionIDs = (function() {
  169. var j, len, results;
  170. results = [];
  171. for (j = 0, len = lionLinks.length; j < len; j++) {
  172. i = lionLinks[j];
  173. results.push(this.getLionID($(i)));
  174. }
  175. return results;
  176. }).call(this);
  177. };
  178.  
  179. LionPlayer.prototype.play = function(arg, playedWith, length) {
  180. var id, ids, recurse, ref;
  181. ref = arg != null ? arg : this.lionIDs, id = ref[0], ids = 2 <= ref.length ? slice.call(ref, 1) : [];
  182. if (playedWith == null) {
  183. playedWith = 0;
  184. }
  185. if (length == null) {
  186. length = ids.length + 1;
  187. }
  188. this.autoPlayLink.text("Loading... (" + playedWith + "/" + length + ")");
  189. recurse = (function(_this) {
  190. return function() {
  191. playedWith++;
  192. if (ids.length) {
  193. return setHumanTimeout(function() {
  194. return _this.play(ids, playedWith, length);
  195. });
  196. } else {
  197. return _this.autoPlayLink.text("Done! (" + playedWith + "/" + length + ")");
  198. }
  199. };
  200. })(this);
  201. return $.get("/lion.php?id=" + id).done((function(_this) {
  202. return function(response) {
  203. if ($(response).find('input[value=Interact]').length) {
  204. return $.post("/lion.php?id=" + id, {
  205. action: 'play',
  206. interact: 'Interact'
  207. }).done(function(response) {
  208. console.log("Played with " + id + " successfully.");
  209. return recurse();
  210. });
  211. } else {
  212. console.log("Couldn't play with " + id + "; probably on cooldown.");
  213. return recurse();
  214. }
  215. };
  216. })(this));
  217. };
  218.  
  219. return LionPlayer;
  220.  
  221. })();
  222. $('a[href^="/lionoverview.php"]').parent().after("<th style=\"text-align:center!important;\"><a href=\"javascript:void(0)\" id=autoPlay>Play with all.</a></th>");
  223. lionPlayer = new LionPlayer($('#autoPlay'));
  224. }