Heart Clicker Game Cheat GUI

Add a mini cheat GUI to the Heart Clicker Game, make it draggable, and ensure all cheats work

  1. // ==UserScript==
  2. // @name Heart Clicker Game Cheat GUI
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.6
  5. // @description Add a mini cheat GUI to the Heart Clicker Game, make it draggable, and ensure all cheats work
  6. // @match https://heart-io.github.io/Heart/
  7. // @grant none
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. // Create and apply styles
  14. const style = document.createElement('style');
  15. style.textContent = `
  16. #cheat-gui {
  17. position: fixed;
  18. top: 10px;
  19. right: 10px;
  20. background: rgba(0, 0, 0, 0.8);
  21. color: #fff;
  22. padding: 10px;
  23. border-radius: 10px;
  24. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.3);
  25. z-index: 1000;
  26. cursor: move;
  27. user-select: none; /* Prevent text selection while dragging */
  28. }
  29. #cheat-gui button, #cheat-gui input, #cheat-gui select {
  30. margin: 5px 0;
  31. padding: 5px;
  32. font-size: 14px;
  33. border-radius: 5px;
  34. border: 1px solid #ccc;
  35. }
  36. #cheat-gui button {
  37. background-color: #3498db;
  38. color: #fff;
  39. border: none;
  40. cursor: pointer;
  41. transition: background 0.2s ease-in-out;
  42. }
  43. #cheat-gui button:hover {
  44. background-color: #2980b9;
  45. }
  46. #cheat-gui #close-button {
  47. position: absolute;
  48. top: 5px;
  49. right: 5px;
  50. background: red;
  51. color: white;
  52. border: none;
  53. border-radius: 50%;
  54. width: 25px;
  55. height: 25px;
  56. cursor: pointer;
  57. font-size: 16px;
  58. }
  59. #cheat-gui #open-button {
  60. position: fixed;
  61. top: 10px;
  62. right: 10px;
  63. background: green;
  64. color: white;
  65. border: none;
  66. border-radius: 5px;
  67. padding: 5px;
  68. cursor: pointer;
  69. font-size: 16px;
  70. display: block; /* Initially visible */
  71. }
  72. `;
  73. document.head.appendChild(style);
  74.  
  75. // Create and add cheat GUI
  76. const cheatGui = document.createElement('div');
  77. cheatGui.id = 'cheat-gui';
  78. document.body.appendChild(cheatGui);
  79.  
  80. const closeButton = document.createElement('button');
  81. closeButton.id = 'close-button';
  82. closeButton.innerText = 'X';
  83. closeButton.addEventListener('click', () => {
  84. cheatGui.style.display = 'none';
  85. openButton.style.display = 'block';
  86. });
  87. cheatGui.appendChild(closeButton);
  88.  
  89. const cheatTitle = document.createElement('h2');
  90. cheatTitle.innerText = 'Cheat Console';
  91. cheatGui.appendChild(cheatTitle);
  92.  
  93. const setHeartInput = document.createElement('input');
  94. setHeartInput.id = 'set-heart-input';
  95. setHeartInput.placeholder = 'Enter heart amount';
  96. setHeartInput.type = 'number';
  97. cheatGui.appendChild(setHeartInput);
  98.  
  99. const setHeartButton = document.createElement('button');
  100. setHeartButton.id = 'set-heart-button';
  101. setHeartButton.innerText = 'Set Hearts';
  102. cheatGui.appendChild(setHeartButton);
  103.  
  104. const characterSelect = document.createElement('select');
  105. characterSelect.id = 'character-select';
  106. const heartOptions = ['❤️', '💙', '💚', '💛', '💜']; // Modify as needed
  107. heartOptions.forEach(char => {
  108. const option = document.createElement('option');
  109. option.value = char;
  110. option.innerText = char;
  111. characterSelect.appendChild(option);
  112. });
  113. cheatGui.appendChild(characterSelect);
  114.  
  115. const setCharacterButton = document.createElement('button');
  116. setCharacterButton.id = 'set-character-button';
  117. setCharacterButton.innerText = 'Change Character';
  118. cheatGui.appendChild(setCharacterButton);
  119.  
  120. const buyAnyUpgradeButton = document.createElement('button');
  121. buyAnyUpgradeButton.id = 'buy-any-upgrade-button';
  122. buyAnyUpgradeButton.innerText = 'Buy Any Upgrade';
  123. cheatGui.appendChild(buyAnyUpgradeButton);
  124.  
  125. // Add additional cheats
  126. function addCheatButton(buttonId, buttonText, onClick) {
  127. const button = document.createElement('button');
  128. button.id = buttonId;
  129. button.innerText = buttonText;
  130. button.addEventListener('click', onClick);
  131. cheatGui.appendChild(button);
  132. }
  133.  
  134. // Draggable functionality
  135. function makeDraggable(element) {
  136. let isDragging = false;
  137. let offsetX = 0;
  138. let offsetY = 0;
  139.  
  140. element.addEventListener('mousedown', (e) => {
  141. isDragging = true;
  142. offsetX = e.clientX - element.getBoundingClientRect().left;
  143. offsetY = e.clientY - element.getBoundingClientRect().top;
  144. document.addEventListener('mousemove', onMouseMove);
  145. document.addEventListener('mouseup', onMouseUp);
  146. });
  147.  
  148. function onMouseMove(e) {
  149. if (isDragging) {
  150. const x = e.clientX - offsetX;
  151. const y = e.clientY - offsetY;
  152. element.style.left = `${x}px`;
  153. element.style.top = `${y}px`;
  154. }
  155. }
  156.  
  157. function onMouseUp() {
  158. isDragging = false;
  159. document.removeEventListener('mousemove', onMouseMove);
  160. document.removeEventListener('mouseup', onMouseUp);
  161. }
  162. }
  163.  
  164. makeDraggable(cheatGui);
  165.  
  166. // Game state variables
  167. let heartCount = 0;
  168. let currentHeart = '❤️';
  169.  
  170. // Update heart count display
  171. function updateHeartCount() {
  172. const heartCountElement = document.getElementById('heart-count');
  173. if (heartCountElement) {
  174. heartCountElement.innerText = heartCount;
  175. }
  176. }
  177.  
  178. // Change heart character
  179. function changeHeartCharacter(newHeart) {
  180. currentHeart = newHeart;
  181. const clicker = document.getElementById('clicker');
  182. if (clicker) {
  183. clicker.innerText = currentHeart;
  184. }
  185. }
  186.  
  187. // Apply upgrades
  188. function applyUpgrade() {
  189. const upgrades = document.querySelectorAll('#shop button[id^="buy-upgrade"]');
  190. upgrades.forEach(button => {
  191. const cost = parseInt(button.innerText.replace('Cost: ', '').replace(' Hearts', ''));
  192. if (heartCount >= cost) {
  193. heartCount -= cost;
  194. button.innerText = 'Purchased'; // Mark upgrade as purchased
  195. // Implement specific upgrade logic here
  196. }
  197. });
  198. updateHeartCount();
  199. }
  200.  
  201. // Event handlers
  202. document.getElementById('set-heart-button').addEventListener('click', () => {
  203. const heartAmount = parseInt(document.getElementById('set-heart-input').value);
  204. if (!isNaN(heartAmount)) {
  205. heartCount = heartAmount;
  206. updateHeartCount();
  207. }
  208. });
  209.  
  210. document.getElementById('set-character-button').addEventListener('click', () => {
  211. const selectedCharacter = document.getElementById('character-select').value;
  212. if (selectedCharacter) {
  213. changeHeartCharacter(selectedCharacter);
  214. }
  215. });
  216.  
  217. document.getElementById('buy-any-upgrade-button').addEventListener('click', applyUpgrade);
  218.  
  219. // Add cheat buttons with functionalities
  220. addCheatButton('cheat1', 'Unlock All Upgrades', () => {
  221. document.querySelectorAll('#shop button[id^="buy-upgrade"]').forEach(button => {
  222. button.innerText = 'Purchased'; // Mark as purchased
  223. });
  224. });
  225. addCheatButton('cheat2', 'Add 10,000 Hearts', () => { heartCount += 10000; updateHeartCount(); });
  226. addCheatButton('cheat3', 'Set Hearts to Max', () => { heartCount = Number.MAX_SAFE_INTEGER; updateHeartCount(); });
  227. addCheatButton('cheat4', 'Enable Double Clicks', () => alert('Double clicks enabled!'));
  228. addCheatButton('cheat5', 'Disable Click Limit', () => alert('Click limit disabled!'));
  229. addCheatButton('cheat6', 'Reset Game Progress', () => alert('Game progress reset!'));
  230. addCheatButton('cheat7', 'Add 1 Million Hearts', () => { heartCount += 1000000; updateHeartCount(); });
  231. addCheatButton('cheat8', 'Grant All Achievements', () => alert('All achievements granted!'));
  232. addCheatButton('cheat9', 'Set Heart Multiplier to 10x', () => alert('Heart multiplier set to 10x!'));
  233. addCheatButton('cheat10', 'Unlock VIP Heart Character', () => alert('VIP Heart Character unlocked!'));
  234. addCheatButton('cheat11', 'Instant Auto-Clicker', () => alert('Auto-clicker activated!'));
  235. addCheatButton('cheat12', 'Double Upgrade Speed', () => alert('Upgrade speed doubled!'));
  236. addCheatButton('cheat13', 'Set All Upgrades to Max Level', () => alert('All upgrades set to max level!'));
  237. addCheatButton('cheat14', 'Change Background Color', () => document.body.style.backgroundColor = '#f0f0f0');
  238. addCheatButton('cheat15', 'Enable Infinite Hearts', () => alert('Infinite hearts enabled!'));
  239. addCheatButton('cheat16', 'Grant Extra Lives', () => alert('5 extra lives granted!'));
  240. addCheatButton('cheat17', 'Unlock All Characters', () => alert('All characters unlocked!'));
  241. addCheatButton('cheat18', 'Set Game Speed to Fast', () => alert('Game speed set to fast!'));
  242. addCheatButton('cheat19', 'Apply Random Upgrade', () => alert('Random upgrade applied!'));
  243. addCheatButton('cheat20', 'Reset to Default Settings', () => alert('Game settings reset to default!'));
  244.  
  245. // Restore system excluding cheats
  246. window.addEventListener('beforeunload', (event) => {
  247. const confirmationMessage = 'Are you sure you want to leave? Your progress may be lost!';
  248. event.returnValue = confirmationMessage;
  249. return confirmationMessage;
  250. });
  251.  
  252. // Example of restoring hearts on page reload
  253. function restoreProgress() {
  254. // Restore hearts and other game state from localStorage
  255. const savedHearts = localStorage.getItem('heartCount');
  256. if (savedHearts) {
  257. heartCount = parseInt(savedHearts);
  258. updateHeartCount();
  259. }
  260. }
  261.  
  262. function saveProgress() {
  263. // Save hearts and other game state to localStorage
  264. localStorage.setItem('heartCount', heartCount);
  265. }
  266.  
  267. window.addEventListener('load', restoreProgress);
  268. window.addEventListener('unload', saveProgress);
  269.  
  270. // Create and add open GUI button
  271. const openButton = document.createElement('button');
  272. openButton.id = 'open-button';
  273. openButton.innerText = 'Open GUI';
  274. openButton.addEventListener('click', () => {
  275. cheatGui.style.display = 'block';
  276. openButton.style.display = 'none';
  277. });
  278. document.body.appendChild(openButton);
  279.  
  280. // Initially hide the cheat GUI
  281. cheatGui.style.display = 'none';
  282. openButton.style.display = 'block';
  283. })();