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.018
  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;
  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(String(percent) + " - " + txt);
  26. }
  27. var startT = function() {
  28. t2 = setInterval(function() {
  29. var minimalMoney = Game.cookiesPs * 42100;
  30. var moneyCanSpend = Game.cookies - minimalMoney;
  31. if (moneyCanSpend < 0) {
  32. _caption('Collecting minimum ' + Beautify(minimalMoney));
  33. _titlePercent(Game.cookies, minimalMoney, 'minimum');
  34. return;
  35. }
  36. var minNewObjectPrice = null;
  37. for (var i in Game.ObjectsById) {
  38. if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
  39. if (Game.ObjectsById[i].locked === 0 && Game.ObjectsById[i].amount === 0) {
  40. var p = Game.ObjectsById[i].price;
  41. if (minNewObjectPrice === null || p < minNewObjectPrice) minNewObjectPrice = p;
  42. }
  43. }
  44. }
  45. var u = null; // upgrade can buy
  46. var minUpgradePrice = null;
  47. for (var g in Game.UpgradesById) {
  48. if (Game.UpgradesById[g].bought === 0 && Game.UpgradesById[g].unlocked == 1) {
  49. //u.push(Game.UpgradesById[g]);
  50. if (minUpgradePrice === null) {
  51. minUpgradePrice = Game.UpgradesById[g].basePrice;
  52. u = g;
  53. } else if (Game.UpgradesById[g].basePrice < minUpgradePrice) {
  54. minUpgradePrice = Game.UpgradesById[g].basePrice;
  55. u = g;
  56. }
  57. }
  58. }
  59. var longTime = (Game.cookiesPs < 100) ? 1 : (
  60. (Game.cookiesPs < 1000) ? 2 : (
  61. (Game.cookiesPs < 10000) ? 3 : (
  62. (Game.cookiesPs < 1E5) ? 4 : (
  63. (Game.cookiesPs < 1E6) ? 5 : (
  64. (Game.cookiesPs < 1E9) ? 10 : 15
  65. )
  66. )
  67. )
  68. )
  69. );
  70. var needUpgrade = (minNewObjectPrice > minUpgradePrice || minUpgradePrice === null) &&
  71. u !== null && typeof Game.UpgradesById[u] !== 'undefined' &&
  72. (moneyCanSpend >= minUpgradePrice || ((minUpgradePrice - moneyCanSpend) / Game.cookiesPs) <= (longTime*60));
  73. if (needUpgrade)
  74. {
  75. if (Game.UpgradesById[u].canBuy()) {
  76. Game.UpgradesById[u].buy();
  77. } else {
  78. _caption('Upgrading ' + Game.UpgradesById[u].name + ' for ' + Beautify(minUpgradePrice));
  79. _titlePercent(moneyCanSpend, minUpgradePrice, Game.UpgradesById[u].name);
  80. }
  81. } else {
  82. var minInvert = null, minObj = null;
  83. for (i in Game.ObjectsById) {
  84. if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
  85. if (Game.ObjectsById[i].locked === 0) {
  86. var interest = Game.ObjectsById[i].price / Game.ObjectsById[i].storedCps;
  87. if (minInvert === null) {
  88. minInvert = interest;
  89. minObj = i;
  90. } else if (interest < minInvert) {
  91. minInvert = interest;
  92. minObj = i;
  93. }
  94. }
  95. }
  96. }
  97. if (minObj !== null) {
  98. Game.ObjectsById[minObj].buy(1);
  99. _caption('Collecting ' + Beautify(Game.ObjectsById[minObj].price) + ' for ' + Game.ObjectsById[minObj].name);
  100. _titlePercent(moneyCanSpend, Game.ObjectsById[minObj].price, Game.ObjectsById[minObj].name);
  101. }
  102. }
  103. }, 1000);
  104. started = true;
  105. _caption('Started');
  106. }
  107. var stopT = function() {
  108. clearInterval(t2);
  109. started = false;
  110. _caption('Collecting gold...');
  111. }
  112. jQuery('#versionNumber').on("click", function() {
  113. if (!started)
  114. startT();
  115. else
  116. stopT();
  117. });
  118. setTimeout(function() {
  119. t3 = setInterval(function() {
  120. var golden = Game.shimmers;
  121. if (golden.length > 0) {
  122. for (var i in golden) {
  123. golden[i].pop();
  124. }
  125. }
  126. }, 1000);
  127. if (Game.cookiesPs < 1E6) {
  128. tClick = setInterval(function() {
  129. Game.mouseX = jQuery('#bigCookie').width() / 2 + jQuery('#bigCookie').offset().left;
  130. Game.mouseY = jQuery('#bigCookie').height() / 2 + jQuery('#bigCookie').offset().top;
  131. Game.ClickCookie();
  132. if (Game.cookiesPs > 1E8) clearInterval(tClick);
  133. }, 300);
  134. }
  135. _caption('Collecting gold...');
  136. }, 5000);
  137. })();