(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 6.0
  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, energyBar, energyBarBar, energyBarChangeBar, energyBarText, energyUpdate, 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. energyBar = $('div.progress:first');
  51.  
  52. energyBarText = energyBar.find('div:last');
  53.  
  54. energyBarText.css('z-index', '2');
  55.  
  56. energyBarBar = energyBar.find('div:first');
  57.  
  58. energyBarBar.css('z-index', '1');
  59.  
  60. energyBarChangeBar = $("<div class=\"progress-bar progress-bar-warning\" role=\"progressbar\" aria-valuenow=\"60\" aria-valuemin=\"0\" aria-valuemax=\"100\" style=\"width: 0%; background: #afc7c7;\" />");
  61.  
  62. energyBar.append(energyBarChangeBar);
  63.  
  64. energyUpdate = function() {
  65. var energyPercent, minutes;
  66. energyPercent = /Energy: ([0-9]+)%/.exec(energyBarText.text())[1];
  67. energyPercent = parseInt(energyPercent);
  68. minutes = new Date(Date.now()).getMinutes();
  69. minutes = 15 - (minutes % 15);
  70. return setTimeout_(minutes * 60 * 1000, function() {
  71. if (energyPercent < 100) {
  72. energyPercent += 10;
  73. }
  74. energyBarText.text("Energy: " + energyPercent + "%");
  75. energyBarChangeBar.css("width", energyPercent + "%");
  76. return energyUpdate();
  77. });
  78. };
  79.  
  80. energyUpdate();
  81.  
  82. moveToToplinks = function(page, linkText) {
  83. var link;
  84. link = navbar.find("a[href='" + page + "']").parent();
  85. link.remove();
  86. link.find('a').text(linkText);
  87. return logout.before(link);
  88. };
  89.  
  90. moveToToplinks('/oasis.php', 'Oasis');
  91.  
  92. moveToToplinks('/boards.php', 'Chatter');
  93.  
  94. moveToToplinks('/news.php', 'News');
  95.  
  96. moveToToplinks('/event.php', 'Event');
  97.  
  98. moveToToplinks('/faq.php', 'FAQ');
  99.  
  100. 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}");
  101.  
  102. newDropdown = function(menuItem, dropdownLinks) {
  103. var dropdown, j, len, link, linkText, ref, results;
  104. if (typeof menuItem === 'string') {
  105. menuItem = navbar.find("a[href='" + menuItem + "']").parent();
  106. }
  107. dropdown = $("<ul class=dropdown></ul>");
  108. menuItem.append(dropdown);
  109. results = [];
  110. for (j = 0, len = dropdownLinks.length; j < len; j++) {
  111. ref = dropdownLinks[j], link = ref[0], linkText = ref[1];
  112. results.push(dropdown.append("<li><a href='" + link + "'>" + linkText + "</a></li>"));
  113. }
  114. return results;
  115. };
  116.  
  117. newNavbarItem = function(page, linkText, dropdownLinks) {
  118. var navbarItem;
  119. navbarItem = $("<li><a href='" + page + "'>" + linkText + "</a></li>");
  120. navbar.append(navbarItem);
  121. if (dropdownLinks != null) {
  122. return newDropdown(navbarItem, dropdownLinks);
  123. }
  124. };
  125.  
  126. 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']]);
  127.  
  128. 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']]);
  129.  
  130. newNavbarItem('/hunting.php', 'Hunting');
  131.  
  132. 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']]);
  133.  
  134. newNavbarItem('/branch.php', 'Branches', [['/branch.php', 'My Branch'], ['/search_branches.php', 'Search']]);
  135.  
  136. newNavbarItem('/territory_map.php', 'Territories');
  137.  
  138. newNavbarItem('/scryingstone.php', 'Scrying Stone', [['/wardrobe.php', 'Wardrobe'], ['/falcons-eye.php', "Falcon's Eye"]]);
  139.  
  140. if (urlMatches(new RegExp('/hunting\\.php', 'i'))) {
  141. minutesLeft = findMatches('div.center > p', 0, 1).text();
  142. getResults = findMatches('input[name=get_results', 0, 1);
  143. if (minutesLeft.length) {
  144. minutesLeft = (/([0-9]+) minutes/.exec(minutesLeft))[1];
  145. minutesLeft = safeParseInt(minutesLeft);
  146. console.log(minutesLeft, 'minutes remaining.');
  147. wait = (minutesLeft + 1) * 60 * 1000;
  148. console.log("Reloading in " + wait + " ms...");
  149. setTimeout_(wait, function() {
  150. return location.reload();
  151. });
  152. } else if (getResults.length) {
  153. blinker = setInterval((function() {
  154. if (document.title === 'Ready!') {
  155. return document.title = '!!!!!!!!!!!!!!!!';
  156. } else {
  157. return document.title = 'Ready!';
  158. }
  159. }), HUNT_BLINK_TIMEOUT);
  160. window.onfocus = function() {
  161. clearInterval(blinker);
  162. return document.title = 'Ready!';
  163. };
  164. }
  165. }
  166.  
  167. if (urlMatches(new RegExp('/territory\\.php', 'i'))) {
  168. LionPlayer = (function() {
  169. LionPlayer.prototype.LION_URL_TO_ID = new RegExp('/lion\\.php.*[?&]id=([0-9]+)');
  170.  
  171. function LionPlayer(autoPlayLink) {
  172. this.autoPlayLink = autoPlayLink;
  173. this.lionIDs = [];
  174. this.safeToClick = true;
  175. this.autoPlayLink.click((function(_this) {
  176. return function() {
  177. return _this.clickListener();
  178. };
  179. })(this));
  180. }
  181.  
  182. LionPlayer.prototype.clickListener = function() {
  183. if (this.safeToClick) {
  184. this.safeToClick = false;
  185. this.updateLionIDs();
  186. return this.play();
  187. }
  188. };
  189.  
  190. LionPlayer.prototype.getLionID = function(lionLink) {
  191. var id, url;
  192. url = lionLink.attr('href');
  193. id = this.LION_URL_TO_ID.exec(url)[1];
  194. return id;
  195. };
  196.  
  197. LionPlayer.prototype.updateLionIDs = function() {
  198. var i, lionLinks;
  199. lionLinks = $('a[href^="/lion.php?id="]');
  200. return this.lionIDs = (function() {
  201. var j, len, results;
  202. results = [];
  203. for (j = 0, len = lionLinks.length; j < len; j++) {
  204. i = lionLinks[j];
  205. results.push(this.getLionID($(i)));
  206. }
  207. return results;
  208. }).call(this);
  209. };
  210.  
  211. LionPlayer.prototype.play = function(arg, playedWith, length) {
  212. var id, ids, recurse, ref;
  213. ref = arg != null ? arg : this.lionIDs, id = ref[0], ids = 2 <= ref.length ? slice.call(ref, 1) : [];
  214. if (playedWith == null) {
  215. playedWith = 0;
  216. }
  217. if (length == null) {
  218. length = ids.length + 1;
  219. }
  220. this.autoPlayLink.text("Loading... (" + playedWith + "/" + length + ")");
  221. recurse = (function(_this) {
  222. return function() {
  223. playedWith++;
  224. if (ids.length) {
  225. return setHumanTimeout(function() {
  226. return _this.play(ids, playedWith, length);
  227. });
  228. } else {
  229. return _this.autoPlayLink.text("Done! (" + playedWith + "/" + length + ")");
  230. }
  231. };
  232. })(this);
  233. return $.get("/lion.php?id=" + id).done((function(_this) {
  234. return function(response) {
  235. if ($(response).find('input[value=Interact]').length) {
  236. return $.post("/lion.php?id=" + id, {
  237. action: 'play',
  238. interact: 'Interact'
  239. }).done(function(response) {
  240. console.log("Played with " + id + " successfully.");
  241. return recurse();
  242. });
  243. } else {
  244. console.log("Couldn't play with " + id + "; probably on cooldown.");
  245. return recurse();
  246. }
  247. };
  248. })(this));
  249. };
  250.  
  251. return LionPlayer;
  252.  
  253. })();
  254. $('a[href^="/lionoverview.php"]').parent().after("<th style=\"text-align:center!important;\"><a href=\"javascript:void(0)\" id=autoPlay>Play with all.</a></th>");
  255. lionPlayer = new LionPlayer($('#autoPlay'));
  256. }