Cookie clicker tools

Cookie clicker tools (visual)

当前为 2017-03-02 提交的版本,查看 最新版本

  1. // ==UserScript==
  2. // @name Cookie clicker tools
  3. // @namespace orteil.dashnet.org
  4. // @version 2.024
  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. if (console) console.log('Cookies?');
  14. var started = false;
  15. var t2, t3, tClick, tClickFrenzy;
  16. var _caption = function(txt) {
  17. var $v = jQuery('#versionNumber');
  18. if ($v.text() != txt) $v.text(txt);
  19. }
  20. var _title = function(txt) {
  21. document.title = txt;
  22. }
  23. var _titlePercent = function(have, need, txt) {
  24. var percent = Math.ceil(have / (need !== 0 ? need : 1) * 100);
  25. _title((percent < 10 ? '00' : (percent < 100 ? '0' : '')) + String(percent) + "% - " + txt);
  26. }
  27. var startT = function() {
  28. t2 = setInterval(function() {
  29. var buffMult = 1;
  30. for (var buff in Game.buffs) {
  31. if (Game.buffs[buff] !== 0 && typeof Game.buffs[buff].multCpS !== 'undefined') {
  32. buffMult = buffMult * Game.buffs[buff].multCpS;
  33. }
  34. }
  35. var normalCookiesPs = Game.cookiesPs / (buffMult !== 0 ? buffMult : 1);
  36. var minimalMoney = normalCookiesPs * 42100;
  37. var moneyCanSpend = Game.cookies - minimalMoney;
  38. if (moneyCanSpend < 0) {
  39. _caption('Collecting minimum ' + Beautify(minimalMoney));
  40. _titlePercent(Game.cookies, minimalMoney, 'minimum');
  41. return;
  42. }
  43. var minNewObjectPrice = null;
  44. for (var i in Game.ObjectsById) {
  45. if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
  46. if (Game.ObjectsById[i].locked === 0 && Game.ObjectsById[i].amount === 0) {
  47. var p = Game.ObjectsById[i].price;
  48. if (minNewObjectPrice === null || p < minNewObjectPrice) minNewObjectPrice = p;
  49. }
  50. }
  51. }
  52. var u = null; // upgrade can buy
  53. var minUpgradePrice = null;
  54. for (var g in Game.UpgradesById) {
  55. if (Game.UpgradesById[g].bought === 0 && Game.UpgradesById[g].unlocked == 1) {
  56. //u.push(Game.UpgradesById[g]);
  57. if (minUpgradePrice === null) {
  58. minUpgradePrice = Game.UpgradesById[g].basePrice;
  59. u = g;
  60. } else if (Game.UpgradesById[g].basePrice < minUpgradePrice) {
  61. minUpgradePrice = Game.UpgradesById[g].basePrice;
  62. u = g;
  63. }
  64. }
  65. }
  66. var longTime = (Game.cookiesPs < 100) ? 1 : (
  67. (Game.cookiesPs < 1000) ? 2 : (
  68. (Game.cookiesPs < 10000) ? 3 : (
  69. (Game.cookiesPs < 1E5) ? 4 : (
  70. (Game.cookiesPs < 1E6) ? 5 : (
  71. (Game.cookiesPs < 1E9) ? 10 : 15
  72. )
  73. )
  74. )
  75. )
  76. );
  77. var needUpgrade = (minNewObjectPrice > minUpgradePrice || minUpgradePrice === null) &&
  78. u !== null && typeof Game.UpgradesById[u] !== 'undefined' &&
  79. (moneyCanSpend >= minUpgradePrice || ((minUpgradePrice - moneyCanSpend) / Game.cookiesPs) <= (longTime*60));
  80. if (needUpgrade)
  81. {
  82. if (Game.UpgradesById[u].canBuy()) {
  83. Game.UpgradesById[u].buy();
  84. } else {
  85. _caption('Upgrading ' + Game.UpgradesById[u].name + ' for ' + Beautify(minUpgradePrice));
  86. _titlePercent(moneyCanSpend, minUpgradePrice, Game.UpgradesById[u].name);
  87. }
  88. } else {
  89. var minInvert = null, minObj = null;
  90. for (i in Game.ObjectsById) {
  91. if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
  92. if (Game.ObjectsById[i].locked === 0) {
  93. var interest = Game.ObjectsById[i].price / Game.ObjectsById[i].storedCps;
  94. if (minInvert === null) {
  95. minInvert = interest;
  96. minObj = i;
  97. } else if (interest < minInvert) {
  98. minInvert = interest;
  99. minObj = i;
  100. }
  101. }
  102. }
  103. }
  104. if (minObj !== null) {
  105. Game.ObjectsById[minObj].buy(1);
  106. _caption('Collecting ' + Beautify(Game.ObjectsById[minObj].price) + ' for ' + Game.ObjectsById[minObj].name);
  107. _titlePercent(moneyCanSpend, Game.ObjectsById[minObj].price, Game.ObjectsById[minObj].name);
  108. }
  109. }
  110. var wrinklersCount = 0, maxWrinkler = -1, maxSucked = 0;
  111. for (i in Game.wrinklers) {
  112. if (Game.wrinklers[i].sucked > 0) {
  113. wrinklersCount++;
  114. /*if (Game.wrinklers[i].sucked > maxSucked) {
  115. maxSucked = Game.wrinklers[i].sucked;
  116. maxWrinkler = i;
  117. }*/
  118. }
  119. }
  120. if (wrinklersCount >= 10) {
  121. //Game.wrinklers[maxWrinkler].hp = 0; // kill
  122. for (i in Game.wrinklers) Game.wrinklers[i].hp = 0; // kill ALL
  123. }
  124. }, 1000);
  125. started = true;
  126. _caption('Started');
  127. }
  128. var stopT = function() {
  129. clearInterval(t2);
  130. started = false;
  131. _caption('Collecting gold...');
  132. }
  133. jQuery('#versionNumber').on("click", function() {
  134. if (!started)
  135. startT();
  136. else
  137. stopT();
  138. });
  139. setTimeout(function() {
  140. t3 = setInterval(function() {
  141. var golden = Game.shimmers;
  142. if (golden.length > 0) {
  143. for (var i in golden) {
  144. golden[i].pop();
  145. }
  146. }
  147. }, 1000);
  148. tClickFrenzy = setInterval(function() {
  149. if (typeof Game.buffs['Click frenzy'] !== 'undefined' && Game.buffs['Click frenzy'] !== 0) {
  150. Game.ClickCookie();
  151. }
  152. }, 75);
  153. if (Game.cookiesPs < 1E6) {
  154. tClick = setInterval(function() {
  155. Game.mouseX = jQuery('#bigCookie').width() / 2 + jQuery('#bigCookie').offset().left;
  156. Game.mouseY = jQuery('#bigCookie').height() / 2 + jQuery('#bigCookie').offset().top;
  157. Game.ClickCookie();
  158. if (Game.cookiesPs > 1E8) clearInterval(tClick);
  159. }, 300);
  160. }
  161. _caption('Collecting gold...');
  162. }, 5000);
  163. })();