Greasy Fork 还支持 简体中文。

Cookie clicker tools

Cookie clicker tools (visual)

目前為 2017-03-03 提交的版本,檢視 最新版本

  1. // ==UserScript==
  2. // @name Cookie clicker tools
  3. // @namespace orteil.dashnet.org
  4. // @version 2.039
  5. // @description Cookie clicker tools (visual)
  6. // @author Anton
  7. // @match http://orteil.dashnet.org/cookieclicker/*
  8. // @require http://ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13. var log = [], logTitle = '<div class="section">Cookies 2.0.39 is here!</div>', newLogs = 0;
  14.  
  15. var started = false, t2, t3, tClick, tClickFrenzy, oldTitle = '';
  16.  
  17. var _getBuffMult = function () {
  18. var buffMult = 1;
  19. for (var buff in Game.buffs) {
  20. if (Game.buffs[buff] !== 0 && typeof Game.buffs[buff].multCpS !== 'undefined') {
  21. buffMult = buffMult * Game.buffs[buff].multCpS;
  22. }
  23. }
  24. return buffMult === 0 ? 1 : buffMult;
  25. }
  26.  
  27. var priorityList = {};
  28. var _createPriorityList = function() {
  29.  
  30. }
  31. var _caption = function(txt) {
  32. var $v = jQuery('#versionNumber');
  33. if ($v.text() != txt) $v.text(txt);
  34. }
  35.  
  36. var _title = function(txt) {
  37. var newTitle = (newLogs > 0 ? '(' + newLogs + ') ' : '') + txt;
  38. if (document.title != newTitle) {
  39. oldTitle = txt;
  40. document.title = newTitle;
  41. }
  42. }
  43.  
  44. var _titlePercent = function(have, need, txt) {
  45. var percent = Math.ceil(have / (need !== 0 ? need : 1) * 100);
  46. _title((percent < 10 ? '00' : (percent < 100 ? '0' : '')) + String(percent) + "% - " + txt);
  47. }
  48.  
  49. var _addLog = function(text) {
  50. var t = new Date();
  51. log.push(t.toUTCString() + ': ' + text);
  52. Game.updateLog = logTitle + '<div class="subsection"><div class="listing">' +
  53. log.join('</div><div class="listing">') + '</div></div>';
  54. newLogs++;
  55. jQuery('#logButton').text('Log (' + newLogs + ')')
  56. _title(oldTitle);
  57. }
  58. jQuery('#logButton').text('Log').on("click", function() {
  59. newLogs = 0;
  60. jQuery('#logButton').text('Log');
  61. });
  62.  
  63. var _getNormalCookiesPs = function () {
  64. return Game.cookiesPs / _getBuffMult();
  65. }
  66.  
  67. var _getMinimalMoney = function () {
  68. return _getNormalCookiesPs() * 42100;
  69. }
  70.  
  71. var _getMoneyCanSpend = function () {
  72. var moneyCanSpend = Game.cookies - _getMinimalMoney();
  73. return moneyCanSpend;
  74. }
  75.  
  76. var _getLongTimeUpgrade = function () {
  77. var moneyCanSpend = _getMoneyCanSpend();
  78. var longTime = (Game.cookiesPs < 100) ? 1 : (
  79. (Game.cookiesPs < 1000) ? 2 : (
  80. (Game.cookiesPs < 10000) ? 3 : (
  81. (Game.cookiesPs < 1E5) ? 4 : (
  82. (Game.cookiesPs < 1E6) ? 5 : (
  83. (Game.cookiesPs < 1E9) ? 10 : 15
  84. )
  85. )
  86. )
  87. )
  88. );
  89. return longTime;
  90. }
  91.  
  92. var _getWrinklerCount = function () {
  93. var wrinklersCount = 0;
  94. for (i in Game.wrinklers) {
  95. if (Game.wrinklers[i].sucked > 0) {
  96. wrinklersCount++;
  97. }
  98. }
  99. return wrinklersCount;
  100. }
  101.  
  102. var _killAllWrinklers = function () {
  103. var wrinklersCount = _getWrinklerCount();
  104. if (wrinklersCount >= 10 || Game.hasBuff('Elder frenzy')) {
  105. var wrinklesIncome = 0;
  106. for (i in Game.wrinklers) {
  107. wrinklesIncome += Game.wrinklers[i].sucked;
  108. Game.wrinklers[i].hp = 0; // kill ALL
  109. }
  110. if (wrinklesIncome > 0) {
  111. _addLog('Killed all Wrinkles for ' + Beautify(wrinklesIncome) + ' because of ' + (Game.hasBuff('Elder frenzy') ? '"Elder frenzy"' : 'count 10.'));
  112. }
  113. }
  114. }
  115.  
  116. var _getMinimalPriceForNewObject = function () {
  117. var minNewObjectPrice = null;
  118. for (var i in Game.ObjectsById) {
  119. if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
  120. if (Game.ObjectsById[i].locked === 0 && Game.ObjectsById[i].amount === 0) {
  121. var p = Game.ObjectsById[i].price;
  122. if (minNewObjectPrice === null || p < minNewObjectPrice) minNewObjectPrice = p;
  123. }
  124. }
  125. }
  126. return minNewObjectPrice;
  127. }
  128. var startT = function() {
  129. t2 = setInterval(function() {
  130.  
  131. _killAllWrinklers();
  132.  
  133. var moneyCanSpend = _getMoneyCanSpend();
  134. if (moneyCanSpend < 0) {
  135. var minimalMoney = _getMinimalMoney();
  136. _caption('Collecting minimum ' + Beautify(minimalMoney));
  137. _titlePercent(Game.cookies, minimalMoney, 'minimum');
  138. return;
  139. }
  140. var minNewObjectPrice = _getMinimalPriceForNewObject();
  141.  
  142. var u = null; // upgrade can buy
  143. var minUpgradePrice = null;
  144. for (var g in Game.UpgradesById) {
  145. if (Game.UpgradesById[g].bought === 0 && Game.UpgradesById[g].unlocked == 1) {
  146. //u.push(Game.UpgradesById[g]);
  147. if (minUpgradePrice === null) {
  148. minUpgradePrice = Game.UpgradesById[g].basePrice;
  149. u = g;
  150. } else if (Game.UpgradesById[g].basePrice < minUpgradePrice) {
  151. minUpgradePrice = Game.UpgradesById[g].basePrice;
  152. u = g;
  153. }
  154. }
  155. }
  156. var longTime = _getLongTimeUpgrade();
  157. var needUpgrade = (minNewObjectPrice > minUpgradePrice || minUpgradePrice === null) &&
  158. u !== null && typeof Game.UpgradesById[u] !== 'undefined' &&
  159. (moneyCanSpend >= minUpgradePrice || ((minUpgradePrice - moneyCanSpend) / _getNormalCookiesPs()) <= (longTime*60));
  160. if (needUpgrade)
  161. {
  162. if (Game.UpgradesById[u].canBuy()) {
  163. Game.UpgradesById[u].buy();
  164. _addLog('Buy upgrade ' + Game.UpgradesById[u].name + ' for ' + Beautify(minUpgradePrice));
  165. } else {
  166. _caption('Upgrading ' + Game.UpgradesById[u].name + ' for ' + Beautify(minUpgradePrice));
  167. _titlePercent(moneyCanSpend, minUpgradePrice, Game.UpgradesById[u].name);
  168. }
  169. } else {
  170. var minInvert = null, minObj = null;
  171. for (i in Game.ObjectsById) {
  172. if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
  173. if (Game.ObjectsById[i].locked === 0) {
  174. var interest = Game.ObjectsById[i].price / Game.ObjectsById[i].storedCps;
  175. if (minInvert === null) {
  176. minInvert = interest;
  177. minObj = i;
  178. } else if (interest < minInvert) {
  179. minInvert = interest;
  180. minObj = i;
  181. }
  182. }
  183. }
  184. }
  185. if (minObj !== null) {
  186. if (Game.ObjectsById[minObj].price < moneyCanSpend) {
  187. Game.ObjectsById[minObj].buy(1);
  188. _addLog('Buy object ' + Game.ObjectsById[minObj].name + ' for ' + Beautify(Game.ObjectsById[minObj].price));
  189. } else {
  190. _caption('Collecting ' + Beautify(Game.ObjectsById[minObj].price) + ' for ' + Game.ObjectsById[minObj].name);
  191. _titlePercent(moneyCanSpend, Game.ObjectsById[minObj].price, Game.ObjectsById[minObj].name);
  192. }
  193. }
  194. }
  195.  
  196. }, 1000);
  197. started = true;
  198. _caption('Started');
  199. _addLog('Autobuy start!');
  200. }
  201. var stopT = function() {
  202. clearInterval(t2);
  203. started = false;
  204. _caption('Collecting gold...');
  205. _addLog('Autobuy stop.');
  206. }
  207. jQuery('#versionNumber').on("click", function() {
  208. if (!started)
  209. startT();
  210. else
  211. stopT();
  212. });
  213. setTimeout(function() {
  214. t3 = setInterval(function() {
  215. var golden = Game.shimmers;
  216. if (golden.length > 0) {
  217. for (var i in golden) {
  218. golden[i].pop();
  219. }
  220. }
  221. }, 1000);
  222. tClickFrenzy = setInterval(function() {
  223. if (Game.hasBuff('Click frenzy') || Game.hasBuff('Cursed finger')) {
  224. Game.ClickCookie();
  225. }
  226. }, 75);
  227. if (Game.cookiesPs < 1E6) {
  228. tClick = setInterval(function() {
  229. Game.mouseX = jQuery('#bigCookie').width() / 2 + jQuery('#bigCookie').offset().left;
  230. Game.mouseY = jQuery('#bigCookie').height() / 2 + jQuery('#bigCookie').offset().top;
  231. Game.ClickCookie();
  232. if (Game.cookiesPs > 1E8) clearInterval(tClick);
  233. }, 300);
  234. }
  235. _caption('Collecting gold...');
  236. }, 5000);
  237. })();