Cookie Clicker Mod Menu

Mod menu for Cookie Clicker.

  1. // ==UserScript==
  2. // @name Cookie Clicker Mod Menu
  3. // @namespace https://orteil.dashnet.org/cookieclicker/
  4. // @version 1.3Beta
  5. // @description Mod menu for Cookie Clicker.
  6. // @author DarkDeath
  7. // @match https://orteil.dashnet.org/cookieclicker/*
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=dashnet.org
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13. (function() {
  14. let clickInterval;
  15. const style = document.createElement('style');
  16. style.textContent = `
  17. #cookie-clicker-menu {
  18. position: fixed;
  19. top: 10px;
  20. right: 10px;
  21. background-color: rgba(0, 0, 0, 0.8);
  22. color: white;
  23. border: 1px solid #ccc;
  24. padding: 10px;
  25. z-index: 1000000;
  26. font-family: Arial, sans-serif;
  27. width: 200px;
  28. }
  29. #cookie-clicker-menu h3 {
  30. margin: 0;
  31. padding-bottom: 10px;
  32. cursor: move;
  33. user-select: none;
  34. border-bottom: 1px solid #ccc;
  35. margin-bottom: 10px;
  36. }
  37. #cookie-clicker-menu button {
  38. display: block;
  39. width: 100%;
  40. margin-bottom: 5px;
  41. padding: 5px;
  42. background-color: #007bff;
  43. color: white;
  44. border: none;
  45. border-radius: 5px;
  46. cursor: pointer;
  47. transition: background-color 0.3s;
  48. }
  49. #cookie-clicker-menu button:hover {
  50. background-color: #0056b3;
  51. }
  52. #ruin-the-fun {
  53. background-color: #dc3545 !important;
  54. }
  55. #ruin-the-fun:hover {
  56. background-color: #c82333 !important;
  57. }
  58. .custom-window {
  59. position: fixed;
  60. top: 50%;
  61. left: 50%;
  62. transform: translate(-50%, -50%);
  63. background-color: rgba(0, 0, 0, 0.9);
  64. color: white;
  65. border: 1px solid #ccc;
  66. padding: 20px;
  67. z-index: 1000001;
  68. font-family: Arial, sans-serif;
  69. width: 300px;
  70. text-align: center;
  71. }
  72. .custom-window input {
  73. width: 100%;
  74. padding: 5px;
  75. margin: 10px 0;
  76. box-sizing: border-box;
  77. }
  78. .custom-window button {
  79. margin: 5px;
  80. padding: 5px 10px;
  81. background-color: #007bff;
  82. color: white;
  83. border: none;
  84. border-radius: 5px;
  85. cursor: pointer;
  86. }
  87. .custom-window button:hover {
  88. background-color: #0056b3;
  89. }
  90. `;
  91. document.head.appendChild(style);
  92.  
  93. const menu = document.createElement('div');
  94. menu.id = 'cookie-clicker-menu';
  95. menu.innerHTML = `
  96. <h3>Cookie Clicker Mod Menu</h3>
  97. <button id="start-auto-click">Start Auto Click</button>
  98. <button id="stop-auto-click">Stop Auto Click</button>
  99. <button id="gain-lumps">Gain Lumps</button>
  100. <button id="buy-times">Buy All</button>
  101. <button id="set-cookies">Set Cookies</button>
  102. <button id="ruin-the-fun">Ruin The Fun</button>
  103. `;
  104. document.body.appendChild(menu);
  105.  
  106. // Make the menu draggable
  107. let isDragging = false;
  108. let currentX;
  109. let currentY;
  110. let initialX;
  111. let initialY;
  112. let xOffset = 0;
  113. let yOffset = 0;
  114.  
  115. menu.querySelector('h3').addEventListener('mousedown', dragStart);
  116. document.addEventListener('mousemove', drag);
  117. document.addEventListener('mouseup', dragEnd);
  118.  
  119. function dragStart(e) {
  120. initialX = e.clientX - xOffset;
  121. initialY = e.clientY - yOffset;
  122. isDragging = true;
  123. }
  124.  
  125. function drag(e) {
  126. if (isDragging) {
  127. e.preventDefault();
  128. currentX = e.clientX - initialX;
  129. currentY = e.clientY - initialY;
  130. xOffset = currentX;
  131. yOffset = currentY;
  132. setTranslate(currentX, currentY, menu);
  133. }
  134. }
  135.  
  136. function dragEnd(e) {
  137. initialX = currentX;
  138. initialY = currentY;
  139. isDragging = false;
  140. }
  141.  
  142. function setTranslate(xPos, yPos, el) {
  143. el.style.transform = `translate3d(${xPos}px, ${yPos}px, 0)`;
  144. }
  145.  
  146. // Custom input window function
  147. function createInputWindow(title, placeholder, callback) {
  148. const inputWindow = document.createElement('div');
  149. inputWindow.className = 'custom-window';
  150. inputWindow.innerHTML = `
  151. <h3>${title}</h3>
  152. <input type="text" placeholder="${placeholder}">
  153. <button class="confirm">Confirm</button>
  154. <button class="cancel">Cancel</button>
  155. `;
  156. document.body.appendChild(inputWindow);
  157.  
  158. const input = inputWindow.querySelector('input');
  159. const confirmBtn = inputWindow.querySelector('.confirm');
  160. const cancelBtn = inputWindow.querySelector('.cancel');
  161.  
  162. confirmBtn.addEventListener('click', () => {
  163. const value = input.value;
  164. document.body.removeChild(inputWindow);
  165. callback(value);
  166. });
  167.  
  168. cancelBtn.addEventListener('click', () => {
  169. document.body.removeChild(inputWindow);
  170. });
  171. }
  172.  
  173. // Custom alert window function
  174. function createAlertWindow(message) {
  175. const alertWindow = document.createElement('div');
  176. alertWindow.className = 'custom-window';
  177. alertWindow.innerHTML = `
  178. <p>${message}</p>
  179. <button class="ok">OK</button>
  180. `;
  181. document.body.appendChild(alertWindow);
  182.  
  183. const okBtn = alertWindow.querySelector('.ok');
  184. okBtn.addEventListener('click', () => {
  185. document.body.removeChild(alertWindow);
  186. });
  187. }
  188.  
  189. // Auto-click functionality
  190. function autoClickCookie(interval) {
  191. if (typeof interval !== 'number' || interval <= 0) {
  192. console.error("Please provide a valid interval in milliseconds.");
  193. return;
  194. }
  195. if (!clickInterval) {
  196. clickInterval = setInterval(() => {
  197. Game.ClickCookie();
  198. }, interval);
  199. } else {
  200. createAlertWindow("Auto clicker is already running.");
  201. }
  202. }
  203.  
  204. function stopAutoClickCookie() {
  205. if (clickInterval) {
  206. clearInterval(clickInterval);
  207. clickInterval = null;
  208. console.log("Auto clicker stopped.");
  209. } else {
  210. console.warn("Auto clicker is not currently running.");
  211. }
  212. }
  213.  
  214. // Gain lumps functionality
  215. function getLumps() {
  216. createInputWindow("Gain Lumps", "Enter number of lumps", (lumps) => {
  217. if (lumps && !isNaN(Number(lumps))) {
  218. Game.gainLumps(Number(lumps));
  219. createAlertWindow(`Gained ${lumps} lumps`);
  220. } else {
  221. createAlertWindow("Please enter a valid number.");
  222. }
  223. });
  224. }
  225.  
  226. // Ruin The Fun functionality
  227. function ruinTheFun() {
  228. if (confirm("Are you sure you want to ruin the fun? This action cannot be undone!")) {
  229. Game.RuinTheFun(1);
  230. createAlertWindow("The fun has been ruined!");
  231. }
  232. }
  233.  
  234. function buyAll() {
  235. Game.storeBuyAll();
  236. createInputWindow("Buy All", "How much do you want to buy?", (times) => {
  237. if (times && !isNaN(Number(times))) {
  238. for (let i in Game.Objects) {
  239. Game.Objects[i].getFree(Number(times));
  240. }
  241. createAlertWindow(`Bought all objects ${times} times.`);
  242. } else {
  243. createAlertWindow("Please enter a valid number.");
  244. }
  245. });
  246. }
  247.  
  248. function setCookies() {
  249. createInputWindow("Set Cookies", "Enter number of cookies", (cookies) => {
  250. if (cookies && !isNaN(Number(cookies))) {
  251. Game.cookies = Number(cookies);
  252. createAlertWindow(`Successfully set your cookies to ${cookies}`);
  253. } else {
  254. createAlertWindow("Please enter a valid number.");
  255. }
  256. });
  257. }
  258.  
  259. // Event listeners for buttons
  260. document.getElementById('start-auto-click').addEventListener('click', () => autoClickCookie(10));
  261. document.getElementById('stop-auto-click').addEventListener('click', stopAutoClickCookie);
  262. document.getElementById('gain-lumps').addEventListener('click', getLumps);
  263. document.getElementById('buy-times').addEventListener('click', buyAll);
  264. document.getElementById('ruin-the-fun').addEventListener('click', ruinTheFun);
  265. document.getElementById('set-cookies').addEventListener('click', setCookies);
  266. console.log("Cookie Clicker mod menu added. Drag the title to move the menu.");
  267. })();