(Sandboxed) Lioden Improvements

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

当前为 2015-09-28 提交的版本,查看 最新版本

  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 3.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, exploringDropdownLinks, getResults, id, linkText, 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. newNavbarItem = function(page, linkText) {
  69. return navbar.append("<li><a href='" + page + "'>" + linkText + "</a></li>");
  70. };
  71.  
  72. newNavbarItem('/hunting.php', 'Hunting');
  73.  
  74. newNavbarItem('/exploring.php', 'Exploring');
  75.  
  76. newNavbarItem('/branch.php', 'Branch');
  77.  
  78. newNavbarItem('/search_branches.php', 'Branches');
  79.  
  80. newNavbarItem('/territory_map.php', 'Territories');
  81.  
  82. GM_addStyle("ul li ul.dropdown {\n min-width: 125px;\n background: #9FAEB5;\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}");
  83.  
  84. newDropdown = function(menuItem, dropdownLinks) {
  85. var dropdown, j, len, link, linkText, ref, results;
  86. console.log('Appending dropdown to', menuItem);
  87. dropdown = $("<ul class=dropdown></ul>");
  88. menuItem.after(dropdown);
  89. results = [];
  90. for (j = 0, len = dropdownLinks.length; j < len; j++) {
  91. ref = dropdownLinks[j], link = ref[0], linkText = ref[1];
  92. results.push(dropdown.append("<li><a href='" + link + "'>" + linkText + "</a></li>"));
  93. }
  94. return results;
  95. };
  96.  
  97. exploringDropdownLinks = [[1, '(1) Temperate S'], [2, '(2-5) Shrubland'], [3, '(6-10) Trpcl Forest'], [4, '(11-15) Dry S'], [5, '(16-20) Rocky Hills'], [6, '(26-30) Marshl.'], [7, '(31+) Waterhole']];
  98.  
  99. exploringDropdownLinks = (function() {
  100. var j, len, ref, results;
  101. results = [];
  102. for (j = 0, len = exploringDropdownLinks.length; j < len; j++) {
  103. ref = exploringDropdownLinks[j], id = ref[0], linkText = ref[1];
  104. results.push(["/explorearea.php?id=" + id, linkText]);
  105. }
  106. return results;
  107. })();
  108.  
  109. newDropdown(navbar.find('a[href="/exploring.php"]'), exploringDropdownLinks);
  110.  
  111. newDropdown(navbar.find('a[href="/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']]);
  112.  
  113. if (urlMatches(new RegExp('/hunting\\.php', 'i'))) {
  114. minutesLeft = findMatches('div.center > p', 0, 1).text();
  115. getResults = findMatches('input[name=get_results', 0, 1);
  116. if (minutesLeft.length) {
  117. minutesLeft = (/([0-9]+) minutes/.exec(minutesLeft))[1];
  118. minutesLeft = safeParseInt(minutesLeft);
  119. console.log(minutesLeft, 'minutes remaining.');
  120. wait = (minutesLeft + 1) * 60 * 1000;
  121. console.log("Reloading in " + wait + " ms...");
  122. setTimeout_(wait, function() {
  123. return location.reload();
  124. });
  125. } else if (getResults.length) {
  126. blinker = setInterval((function() {
  127. if (document.title === 'Ready!') {
  128. return document.title = '!!!!!!!!!!!!!!!!';
  129. } else {
  130. return document.title = 'Ready!';
  131. }
  132. }), HUNT_BLINK_TIMEOUT);
  133. window.onfocus = function() {
  134. clearInterval(blinker);
  135. return document.title = 'Ready!';
  136. };
  137. }
  138. }
  139.  
  140. if (urlMatches(new RegExp('/territory\\.php', 'i'))) {
  141. LionPlayer = (function() {
  142. LionPlayer.prototype.LION_URL_TO_ID = new RegExp('/lion\\.php.*[?&]id=([0-9]+)');
  143.  
  144. function LionPlayer(autoPlayLink) {
  145. this.autoPlayLink = autoPlayLink;
  146. this.lionIDs = [];
  147. this.safeToClick = true;
  148. this.autoPlayLink.click((function(_this) {
  149. return function() {
  150. return _this.clickListener();
  151. };
  152. })(this));
  153. }
  154.  
  155. LionPlayer.prototype.clickListener = function() {
  156. if (this.safeToClick) {
  157. this.safeToClick = false;
  158. this.updateLionIDs();
  159. return this.play();
  160. }
  161. };
  162.  
  163. LionPlayer.prototype.getLionID = function(lionLink) {
  164. var url;
  165. url = lionLink.attr('href');
  166. id = this.LION_URL_TO_ID.exec(url)[1];
  167. return id;
  168. };
  169.  
  170. LionPlayer.prototype.updateLionIDs = function() {
  171. var i, lionLinks;
  172. lionLinks = $('a[href^="/lion.php?id="]');
  173. return this.lionIDs = (function() {
  174. var j, len, results;
  175. results = [];
  176. for (j = 0, len = lionLinks.length; j < len; j++) {
  177. i = lionLinks[j];
  178. results.push(this.getLionID($(i)));
  179. }
  180. return results;
  181. }).call(this);
  182. };
  183.  
  184. LionPlayer.prototype.play = function(arg, playedWith, length) {
  185. var id, ids, recurse, ref;
  186. ref = arg != null ? arg : this.lionIDs, id = ref[0], ids = 2 <= ref.length ? slice.call(ref, 1) : [];
  187. if (playedWith == null) {
  188. playedWith = 0;
  189. }
  190. if (length == null) {
  191. length = ids.length + 1;
  192. }
  193. this.autoPlayLink.text("Loading... (" + playedWith + "/" + length + ")");
  194. recurse = (function(_this) {
  195. return function() {
  196. playedWith++;
  197. if (ids.length) {
  198. return setHumanTimeout(function() {
  199. return _this.play(ids, playedWith, length);
  200. });
  201. } else {
  202. return _this.autoPlayLink.text("Done! (" + playedWith + "/" + length + ")");
  203. }
  204. };
  205. })(this);
  206. return $.get("/lion.php?id=" + id).done((function(_this) {
  207. return function(response) {
  208. if ($(response).find('input[value=Interact]').length) {
  209. return $.post("/lion.php?id=" + id, {
  210. action: 'play',
  211. interact: 'Interact'
  212. }).done(function(response) {
  213. console.log("Played with " + id + " successfully.");
  214. return recurse();
  215. });
  216. } else {
  217. console.log("Couldn't play with " + id + "; probably on cooldown.");
  218. return recurse();
  219. }
  220. };
  221. })(this));
  222. };
  223.  
  224. return LionPlayer;
  225.  
  226. })();
  227. $('a[href^="/lionoverview.php"]').parent().after("<th style=\"text-align:center!important;\"><a href=\"javascript:void(0)\" id=autoPlay>Play with all.</a></th>");
  228. lionPlayer = new LionPlayer($('#autoPlay'));
  229. }