Greasy Fork 还支持 简体中文。

Cookie clicker tools

Cookie clicker tools (visual)

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

  1. // ==UserScript==
  2. // @name Cookie clicker tools
  3. // @namespace orteil.dashnet.org
  4. // @version 2.094
  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">Cookie clicker tools 2.094 is here!</div>', newLogs = 0;
  14.  
  15. var started = false, t2, t3, tClick, tClickFrenzy, oldTitle = '', tLog,
  16. tPriority;
  17.  
  18. var _history = function() {
  19. var hist = [];
  20. hist.push('2.094 - objects CpS fix (buffs)');
  21. hist.push('2.093 - objects CpS fix');
  22. hist.push('2.092 - priority table fix');
  23. hist.push('2.091 - priority table refactor');
  24. hist.push('2.090 - buy very cheap items first');
  25. hist.push('2.089 - fix pool toggle buy');
  26. hist.push('2.088 - fix');
  27. hist.push('2.087 - fix buy unknown upgrades');
  28. hist.push('2.086 - clear log button');
  29. hist.push('2.085 - fix');
  30. hist.push('2.084 - buy unknown upgrades if their price is 0.1% of cookie storage');
  31. hist.push('2.083 - mouse upgrades is processed as Upgrades');
  32. hist.push('2.082 - start from scratch');
  33. hist.push('2.081 - fix');
  34. hist.push('2.080 - add history, add option "showTimeCompensate"');
  35. hist.push('2.079 - hide donate box');
  36. hist.push('2.078 - Kittens now is processed as Upgrades');
  37. hist.push('');
  38. hist.push('');
  39. return hist;
  40. }
  41.  
  42. var _getKittenPercentByUpgradeName = function(kName) {
  43. if (kName == 'Kitten helpers') return Game.milkProgress*0.1;
  44. if (kName == 'Kitten workers') return Game.milkProgress*0.125;
  45. if (kName == 'Kitten engineers') return Game.milkProgress*0.15;
  46. if (kName == 'Kitten overseers') return Game.milkProgress*0.175;
  47. if (kName == 'Kitten managers') return Game.milkProgress*0.2;
  48. if (kName == 'Kitten accountants') return Game.milkProgress*0.2;
  49. if (kName == 'Kitten specialists') return Game.milkProgress*0.2;
  50. if (kName == 'Kitten experts') return Game.milkProgress*0.2;
  51. if (kName == 'Kitten angels') return Game.milkProgress*0.1;
  52. return 0;
  53. }
  54.  
  55. var options = {
  56. bankStoragePercent: 100,
  57. showTimeCompensate: false
  58. };
  59. var _store = function(name, value) {
  60. if (typeof(Storage) !== "undefined") localStorage.setItem(name, value);
  61. };
  62. var _restore = function(name) {
  63. if (typeof(Storage) !== "undefined") return localStorage.getItem(name);
  64. else return undefined;
  65. };
  66.  
  67. var _getBuffMult = function () {
  68. var buffMult = 1;
  69. for (var buff in Game.buffs) {
  70. if (Game.buffs[buff] !== 0 && typeof Game.buffs[buff].multCpS !== 'undefined') {
  71. buffMult = buffMult * Game.buffs[buff].multCpS;
  72. }
  73. }
  74. return buffMult === 0 ? 1 : buffMult;
  75. };
  76.  
  77. var _getNormalCookiesPs = function () {
  78. return Game.cookiesPs / _getBuffMult();
  79. };
  80.  
  81. var _getMinimalMoney = function () {
  82. return Math.floor(_getNormalCookiesPs() * 42100 * options.bankStoragePercent / 100);
  83. };
  84.  
  85. var _getMoneyCanSpend = function () {
  86. var moneyCanSpend = Game.cookies - _getMinimalMoney();
  87. return moneyCanSpend;
  88. };
  89.  
  90. var priorityListObj = {}, priorityList = [], timeCompensateObj = {}, timeCompensateList = [];
  91. var _createPriorityList = function() {
  92. var moneyCanSpend = _getMoneyCanSpend();
  93. var money = Game.cookies;
  94. var buffMult = _getBuffMult();
  95. priorityList = [];
  96. priorityListObj = {};
  97. for (var g in Game.UpgradesById) {
  98. if (Game.UpgradesById[g].bought === 0 && Game.UpgradesById[g].unlocked == 1) {
  99. var isMultiplier = Game.UpgradesById[g].desc.indexOf('production multiplier') >= 0;
  100. var isDouble = Game.UpgradesById[g].desc.indexOf('<b>twice</b>') >= 0;
  101. var isDoubleGrandma = Game.UpgradesById[g].desc.indexOf('Grandmas are <b>twice</b>') >= 0;
  102. var isKitten = Game.UpgradesById[g].name.indexOf('Kitten ') >= 0;
  103. var isDoubleCursor = Game.UpgradesById[g].desc.indexOf('The mouse and cursors are <b>twice</b>') >= 0;
  104. var increasedMoney = 0;
  105. if (isDoubleCursor) {
  106. increasedMoney = Game.Objects['Cursor'].storedTotalCps * Game.globalCpsMult / buffMult;
  107. } else if (isKitten) {
  108. var kittenPercent = _getKittenPercentByUpgradeName(Game.UpgradesById[g].name);
  109. increasedMoney = _getNormalCookiesPs() * kittenPercent;
  110. } else if (isDoubleGrandma) {
  111. increasedMoney = Game.Objects['Grandma'].storedTotalCps * Game.globalCpsMult / buffMult;
  112. } else if (isMultiplier) {
  113. increasedMoney = _getNormalCookiesPs() * Game.UpgradesById[g].power / 100;
  114. } else if (isDouble) {
  115. increasedMoney = Game.UpgradesById[g].buildingTie.storedTotalCps * Game.globalCpsMult / buffMult;
  116. }
  117. var interest = increasedMoney > 0 ? Game.UpgradesById[g].basePrice / increasedMoney : '-';
  118. if (interest != '-') {
  119. if (typeof priorityListObj[Math.floor(interest)] === 'undefined') {
  120. priorityListObj[Math.floor(interest)] = {
  121. name: Game.UpgradesById[g].name,
  122. title: Game.UpgradesById[g].name + ' - ' + Beautify(Game.UpgradesById[g].basePrice),
  123. price: Game.UpgradesById[g].basePrice,
  124. cps: 1,
  125. type: 'upgrade',
  126. id: g,
  127. income: increasedMoney
  128. };
  129. }
  130. } else if (Game.UpgradesById[g].type == 'upgrade' &&
  131. Game.UpgradesById[g].basePrice < moneyCanSpend &&
  132. Game.UpgradesById[g].pool != 'toggle')
  133. {
  134. interest = Game.UpgradesById[g].basePrice / moneyCanSpend * 1000;
  135. if (typeof priorityListObj[Math.floor(interest)] === 'undefined') {
  136. priorityListObj[Math.floor(interest)] = {
  137. name: Game.UpgradesById[g].name,
  138. title: Game.UpgradesById[g].name + ' - ' + Beautify(Game.UpgradesById[g].basePrice),
  139. price: Game.UpgradesById[g].basePrice,
  140. cps: 1,
  141. type: 'upgrade',
  142. id: g,
  143. income: 0
  144. };
  145. }
  146. }
  147. //priorityList.push(Game.UpgradesById[g].name + ' - ' + Beautify(Game.UpgradesById[g].basePrice) + ' (INTEREST: ' + Beautify(interest) + ')');
  148. }
  149. }
  150. for (var i in Game.ObjectsById) {
  151. if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
  152. if (Game.ObjectsById[i].locked === 0) {
  153. var cps = (Game.ObjectsById[i].storedTotalCps/Game.ObjectsById[i].amount) * Game.globalCpsMult;
  154. interest = Game.ObjectsById[i].price / cps;
  155. var pp = moneyCanSpend / Game.ObjectsById[i].price; // percent of cheapness
  156. if (pp > 50) interest /= pp * 50;
  157. priorityListObj[Math.floor(interest)] = {
  158. name: Game.ObjectsById[i].name,
  159. title: Game.ObjectsById[i].name + ' - ' + Beautify(Game.ObjectsById[i].price),
  160. price: Game.ObjectsById[i].price,
  161. cps: cps,
  162. type: 'buy',
  163. id: i,
  164. income: cps
  165. };
  166. //priorityList.push(Game.ObjectsById[i].name + ' - ' + Beautify(Game.ObjectsById[i].price) + ' (INTEREST: ' + Beautify(interest) + ')');
  167. }
  168. }
  169. }
  170. for (i in priorityListObj) {
  171. var prefix = priorityListObj[i].price < moneyCanSpend ? '!!! ' : (priorityListObj[i].price < money ? '! ' : '');
  172. var pp = Math.floor(moneyCanSpend / priorityListObj[i].price * 100);
  173. priorityList.push(prefix + priorityListObj[i].title + ' : ' + i + ' (' + pp + '%)');
  174. }
  175.  
  176. timeCompensateObj = {};
  177. timeCompensateList = [];
  178. for (i in priorityListObj) {
  179. var o = priorityListObj[i];
  180. if (o.type == 'buy') {
  181. var cpsWithPercent = (o.cps / _getNormalCookiesPs() + 1) * o.cps;
  182. var interestNew = o.price / cpsWithPercent;
  183. timeCompensateObj[Math.floor(interestNew)] = {
  184. name: o.name,
  185. title: o.title,
  186. price: o.price,
  187. cps: cpsWithPercent,
  188. type: 'buy',
  189. id: o.id,
  190. income: o.income
  191. };
  192. } else {
  193. timeCompensateObj[i] = o;
  194. }
  195. }
  196. for (i in timeCompensateObj) {
  197. prefix = timeCompensateObj[i].price < moneyCanSpend ? '!!! ' : (timeCompensateObj[i].price < money ? '! ' : '');
  198. timeCompensateList.push(prefix + timeCompensateObj[i].title + ' : ' + i);
  199. }
  200. };
  201.  
  202. var _caption = function(txt) {
  203. var $v = jQuery('#versionNumber');
  204. if ($v.text() != txt) $v.text(txt);
  205. };
  206.  
  207. var _title = function(txt) {
  208. var newTitle = (newLogs > 0 ? '(' + newLogs + ') ' : '') + txt;
  209. if (document.title != newTitle) {
  210. oldTitle = txt;
  211. document.title = newTitle;
  212. }
  213. };
  214.  
  215. var _titlePercent = function(have, need, txt) {
  216. var percent = Math.ceil(have / (need !== 0 ? need : 1) * 100);
  217. _title(String(percent) + "% - " + txt);
  218. };
  219.  
  220. var _logSectionTitle = function (text) {
  221. return '<div class="title">' + text + '</div>';
  222. };
  223.  
  224. var _logSection = function (title, items) {
  225. return '<div class="subsection">' + _logSectionTitle(title) +
  226. '<div class="listing">' + items.join('</div><div class="listing">') + '</div>' +
  227. '</div>';
  228. };
  229. var clearLogButton = '<button data-id="clearLog" onclick="document.getElementById(\'logButton\').onbuttonclick(this,event)">Clear Log</button>';
  230.  
  231. var _logPriorityTable = function() {
  232. var moneyCanSpend = _getMoneyCanSpend();
  233. var styles = '<style type="text/css">.prioritytable{width:100%;}.prioritytable td,.prioritytable th{padding:3px;}</style>';
  234. var t = '<table class="prioritytable"><tr style="border-bottom:1px solid;text-align:left;font-weight:bold;"><th>Type</th><th>Name</th><th>Price</th><th>Interest</th><th>Income</th><th>% bank</th></tr>';
  235. for (i in priorityListObj) {
  236. var o = priorityListObj[i];
  237. var pp = Math.floor(moneyCanSpend / o.price * 100);
  238. t += '<tr><td>' + o.type + '</td><td>' + o.name + '</td><td>' + Beautify(o.price) + '</td><td>' + i + '</td><td>' + Beautify(o.income) + '</td><td>' + pp + '</td></tr>';
  239. }
  240. t += '</table>';
  241. return styles + '<div class="subsection">' + _logSectionTitle('Priority ' + clearLogButton) + '<div class="listing">' + t + '</div></div>';
  242. }
  243. var _optionsSection = function() {
  244. var content = [];
  245. content.push('<label for="bankStoragePercent" id="bankStoragePercentLabel">Storage (' + Beautify(_getMinimalMoney()) + ') percent: ' + options.bankStoragePercent + '%</label> <input name="bankStoragePercent" id="bankStoragePercent" type="range" min="0" max="100" value="' + options.bankStoragePercent + '" onchange="document.getElementById(\'logButton\').onsliderchange(this)" />');
  246. content.push('<button data-id="showTimeCompensate" onclick="document.getElementById(\'logButton\').onbuttonclick(this,event)">showTimeCompensate: ' + (options.showTimeCompensate ? 'TRUE' : 'FALSE') + '</button>');
  247. content.push(clearLogButton);
  248. return content;
  249. };
  250.  
  251. var _updateLog = function () {
  252. Game.updateLog = logTitle +
  253. //_logSection('Priority ' + clearLogButton, priorityList) +
  254. _logPriorityTable() +
  255. (options.showTimeCompensate ? _logSection('Priority (time compensate)', timeCompensateList) : '') +
  256. _logSection('Log', log) +
  257. _logSection('Options', _optionsSection()) +
  258. _logSection('History', _history());
  259. var newButtonText = newLogs > 0 ? 'Log (' + newLogs + ')' : 'Log';
  260. if (jQuery('#logButton').text() != newButtonText) jQuery('#logButton').text(newButtonText);
  261. _title(oldTitle);
  262. };
  263.  
  264. document.getElementById('logButton').onsliderchange = function(el) {
  265. var val = $(el).val();
  266. _store('bankStoragePercent', val);
  267. options.bankStoragePercent = val;
  268. jQuery('#bankStoragePercentLabel').text('Storage (' + Beautify(_getMinimalMoney()) + ') percent: ' + val + '%');
  269. _updateLog();
  270. };
  271. document.getElementById('logButton').onbuttonclick = function(el,e) {
  272. e.preventDefault();
  273. var id = jQuery(el).attr('data-id');
  274. if (id == 'showTimeCompensate') {
  275. options.showTimeCompensate = !options.showTimeCompensate;
  276. } else if (id == 'clearLog') {
  277. log = [];
  278. newLogs = 0;
  279. }
  280. jQuery(el).attr('disabled', 'disabled');
  281. _updateLog();
  282. }
  283.  
  284. tPriority = setInterval(function () {
  285. _createPriorityList();
  286. _updateLog();
  287. }, 1000);
  288.  
  289. var _addLog = function(text) {
  290. var t = new Date();
  291. log.push(t.toUTCString() + ': ' + text);
  292. newLogs++;
  293. _updateLog();
  294. };
  295.  
  296. tLog = setInterval(function () {
  297. _updateLog();
  298. }, 600);
  299.  
  300. jQuery('#logButton').text('Log').on("click", function() {
  301. newLogs = 0;
  302. jQuery('#logButton').text('Log');
  303. });
  304.  
  305. var _getLongTimeUpgrade = function () {
  306. var moneyCanSpend = _getMoneyCanSpend();
  307. var longTime = (Game.cookiesPs < 100) ? 1 : (
  308. (Game.cookiesPs < 1000) ? 2 : (
  309. (Game.cookiesPs < 10000) ? 3 : (
  310. (Game.cookiesPs < 1E5) ? 4 : (
  311. (Game.cookiesPs < 1E6) ? 5 : (
  312. (Game.cookiesPs < 1E9) ? 10 : 15
  313. )
  314. )
  315. )
  316. )
  317. );
  318. return longTime;
  319. };
  320.  
  321. var _getWrinklerCount = function () {
  322. var wrinklersCount = 0;
  323. for (var i in Game.wrinklers) {
  324. if (Game.wrinklers[i].sucked > 0) {
  325. wrinklersCount++;
  326. }
  327. }
  328. return wrinklersCount;
  329. };
  330.  
  331. var _killAllWrinklers = function () {
  332. var wrinklersCount = _getWrinklerCount();
  333. if (wrinklersCount >= 10 || Game.hasBuff('Elder frenzy')) {
  334. var wrinklesIncome = 0;
  335. for (var i in Game.wrinklers) {
  336. wrinklesIncome += Game.wrinklers[i].sucked;
  337. Game.wrinklers[i].hp = 0; // kill ALL
  338. }
  339. if (wrinklesIncome > 0) {
  340. _addLog('Killed all Wrinkles for ' + Beautify(wrinklesIncome) + ' because of ' + (Game.hasBuff('Elder frenzy') ? '"Elder frenzy"' : 'count 10.'));
  341. }
  342. }
  343. };
  344.  
  345. var _getMinimalPriceForNewObject = function () {
  346. var minNewObjectPrice = null;
  347. for (var i in Game.ObjectsById) {
  348. if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
  349. if (Game.ObjectsById[i].locked === 0 && Game.ObjectsById[i].amount === 0) {
  350. var p = Game.ObjectsById[i].price;
  351. if (minNewObjectPrice === null || p < minNewObjectPrice) minNewObjectPrice = p;
  352. }
  353. }
  354. }
  355. return minNewObjectPrice;
  356. };
  357.  
  358. var startT = function() {
  359. t2 = setInterval(function() {
  360.  
  361. _killAllWrinklers();
  362.  
  363. var moneyCanSpend = _getMoneyCanSpend();
  364.  
  365. if (moneyCanSpend < 0) {
  366. var minimalMoney = _getMinimalMoney();
  367. _caption('Collecting minimum ' + Beautify(minimalMoney));
  368. _titlePercent(Game.cookies, minimalMoney, 'minimum');
  369. return;
  370. }
  371. if (priorityList.length > 0) {
  372. for (var idx in priorityListObj) {
  373. var needToBuy = priorityListObj[idx];
  374. if (needToBuy.type == 'upgrade') {
  375. _caption('Upgrading ' + needToBuy.name + ' for ' + Beautify(needToBuy.price));
  376. if (needToBuy.price < moneyCanSpend) {
  377. if (Game.UpgradesById[needToBuy.id].canBuy()) {
  378. Game.UpgradesById[needToBuy.id].buy();
  379. _addLog('Buy upgrade ' + Game.UpgradesById[needToBuy.id].name + ' for ' + Beautify(needToBuy.price));
  380. _createPriorityList();
  381. }
  382. } else {
  383. _titlePercent(moneyCanSpend, needToBuy.price, Game.UpgradesById[needToBuy.id].name);
  384. }
  385. } else {
  386. _caption('Collecting ' + Beautify(needToBuy.price) + ' for ' + needToBuy.name);
  387. if (Game.ObjectsById[needToBuy.id].price < moneyCanSpend) {
  388. Game.ObjectsById[needToBuy.id].buy(1);
  389. _addLog('Buy object ' + Game.ObjectsById[needToBuy.id].name + ' for ' + Beautify(Game.ObjectsById[needToBuy.id].price));
  390. _createPriorityList();
  391. } else {
  392. _titlePercent(moneyCanSpend, needToBuy.price, Game.ObjectsById[needToBuy.id].name);
  393. }
  394. }
  395. break;
  396. }
  397. return;
  398. }
  399.  
  400. var minNewObjectPrice = _getMinimalPriceForNewObject();
  401.  
  402. var u = null; // upgrade can buy
  403. var minUpgradePrice = null;
  404. for (var g in Game.UpgradesById) {
  405. if (Game.UpgradesById[g].bought === 0 && Game.UpgradesById[g].unlocked == 1) {
  406. //u.push(Game.UpgradesById[g]);
  407. if (minUpgradePrice === null) {
  408. minUpgradePrice = Game.UpgradesById[g].basePrice;
  409. u = g;
  410. } else if (Game.UpgradesById[g].basePrice < minUpgradePrice) {
  411. minUpgradePrice = Game.UpgradesById[g].basePrice;
  412. u = g;
  413. }
  414. }
  415. }
  416.  
  417. var longTime = _getLongTimeUpgrade();
  418. var needUpgrade = (minNewObjectPrice > minUpgradePrice || minUpgradePrice === null) &&
  419. u !== null && typeof Game.UpgradesById[u] !== 'undefined' &&
  420. (moneyCanSpend >= minUpgradePrice || ((minUpgradePrice - moneyCanSpend) / _getNormalCookiesPs()) <= (longTime*60));
  421.  
  422. if (needUpgrade)
  423. {
  424. if (Game.UpgradesById[u].canBuy()) {
  425. Game.UpgradesById[u].buy();
  426. _addLog('Buy upgrade ' + Game.UpgradesById[u].name + ' for ' + Beautify(minUpgradePrice));
  427. } else {
  428. _caption('Upgrading ' + Game.UpgradesById[u].name + ' for ' + Beautify(minUpgradePrice));
  429. _titlePercent(moneyCanSpend, minUpgradePrice, Game.UpgradesById[u].name);
  430. }
  431. } else {
  432. var minInvert = null, minObj = null;
  433. for (var i in Game.ObjectsById) {
  434. if (typeof i !== 'undefined' && i != 'undefined' && Game.ObjectsById.hasOwnProperty(i)) {
  435. if (Game.ObjectsById[i].locked === 0) {
  436. var interest = Game.ObjectsById[i].price / Game.ObjectsById[i].storedCps;
  437. if (minInvert === null) {
  438. minInvert = interest;
  439. minObj = i;
  440. } else if (interest < minInvert) {
  441. minInvert = interest;
  442. minObj = i;
  443. }
  444. }
  445. }
  446. }
  447. if (minObj !== null) {
  448. if (Game.ObjectsById[minObj].price < moneyCanSpend) {
  449. Game.ObjectsById[minObj].buy(1);
  450. _addLog('Buy object ' + Game.ObjectsById[minObj].name + ' for ' + Beautify(Game.ObjectsById[minObj].price));
  451. } else {
  452. _caption('Collecting ' + Beautify(Game.ObjectsById[minObj].price) + ' for ' + Game.ObjectsById[minObj].name);
  453. _titlePercent(moneyCanSpend, Game.ObjectsById[minObj].price, Game.ObjectsById[minObj].name);
  454. }
  455. }
  456.  
  457. }
  458.  
  459. }, 1000);
  460.  
  461. started = true;
  462. _caption('Started');
  463. _addLog('Autobuy start!');
  464. };
  465.  
  466. var stopT = function() {
  467. clearInterval(t2);
  468. started = false;
  469. _caption('Collecting gold...');
  470. _addLog('Autobuy stop.');
  471. };
  472.  
  473. jQuery('#versionNumber').on("click", function() {
  474. if (!started)
  475. startT();
  476. else
  477. stopT();
  478. });
  479.  
  480. options.bankStoragePercent = _restore('bankStoragePercent');
  481. if (typeof options.bankStoragePercent === 'undefined' || options.bankStoragePercent === null) {
  482. options.bankStoragePercent = 100;
  483. }
  484.  
  485. setTimeout(function() {
  486. jQuery('#donateBox').hide();
  487. t3 = setInterval(function() {
  488. var golden = Game.shimmers;
  489. if (golden.length > 0) {
  490. for (var i in golden) {
  491. golden[i].pop();
  492. }
  493. }
  494. }, 500);
  495.  
  496. tClickFrenzy = setInterval(function() {
  497. if (Game.hasBuff('Click frenzy') || Game.hasBuff('Cursed finger') || Game.cookiesPs < 1000000) {
  498. Game.ClickCookie();
  499. }
  500. }, 75);
  501.  
  502. if (Game.cookiesPs < 1E6) {
  503. tClick = setInterval(function() {
  504. Game.mouseX = jQuery('#bigCookie').width() / 2 + jQuery('#bigCookie').offset().left;
  505. Game.mouseY = jQuery('#bigCookie').height() / 2 + jQuery('#bigCookie').offset().top;
  506. Game.ClickCookie();
  507. if (Game.cookiesPs > 1E8) clearInterval(tClick);
  508. }, 300);
  509. }
  510.  
  511. _caption('Collecting gold...');
  512. }, 5000);
  513. })();