Cookie clicker tools

Cookie clicker tools (visual)

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

  1. // ==UserScript==
  2. // @name Cookie clicker tools
  3. // @namespace orteil.dashnet.org
  4. // @version 1.93
  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 t = setInterval(function() {
  15. var icons = document.querySelectorAll('.icon:not([id^=product])');
  16. var x = icons && icons.length > 0 ? icons[0].offsetParent : null;
  17. if (x !== null) {
  18. var $tooltip = jQuery(x);
  19. var price = $tooltip.find('span.price').text();
  20. if (price) {
  21. price = price.replace(',', '');
  22. var priceNum = parseFloat(price);
  23. var mult = 1;
  24. if (price.indexOf('billion') > -1) mult = 1E9;
  25. else if (price.indexOf('million') > -1) mult = 1E6;
  26. var totalPrice = priceNum * mult;
  27.  
  28. var data = $tooltip.find('div.data b');
  29. var eachIncome = jQuery(data[0]).text().replace(',', '');
  30. var eachIncomeNum = parseFloat(eachIncome);
  31. mult = 1;
  32. if (eachIncome.indexOf('billion') > -1) mult = 1E9;
  33. else if (eachIncome.indexOf('million') > -1) mult = 1E6;
  34. var totalIncome = eachIncomeNum * mult;
  35. var needed = totalPrice > 0 ? totalIncome / totalPrice : 0;
  36. var needInvert = totalIncome > 0 ? totalPrice / totalIncome : 0;
  37. var $name = $tooltip.find('div.name span');
  38. if ($name.length === 0) {
  39. $tooltip.find('div.name').append(jQuery('<span />'));
  40. $name = $tooltip.find('div.name span');
  41. }
  42. $name.text(' (' + Beautify(needInvert) + ')');
  43. }
  44. }
  45. }, 100);
  46. })();