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.5
  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. #close-button, #open-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. display: none; /* Hidden by default */
  59. }
  60. #open-button {
  61. background: green;
  62. display: block; /* Initially visible */
  63. }
  64. `;
  65. document.head.appendChild(style);
  66.  
  67. // Create and add cheat GUI
  68. const cheatGui = document.createElement('div');
  69. cheatGui.id = 'cheat-gui';
  70. document.body.appendChild(cheatGui);
  71.  
  72. const closeButton = document.createElement('button');
  73. closeButton.id = 'close-button';
  74. closeButton.innerText = 'X';
  75. closeButton.addEventListener('click', () => {
  76. cheatGui.style.display = 'none';
  77. openButton.style.display = 'block';
  78. });
  79. cheatGui.appendChild(closeButton);
  80.  
  81. const openButton = document.createElement('button');
  82. openButton.id = 'open-button';
  83. openButton.innerText = 'Open GUI';
  84. openButton.addEventListener('click', () => {
  85. cheatGui.style.display = 'block';
  86. openButton.style.display = 'none';
  87. });
  88. document.body.appendChild(openButton);
  89.  
  90. const cheatTitle = document.createElement('h2');
  91. cheatTitle.innerText = 'Cheat Console';
  92. cheatGui.appendChild(cheatTitle);
  93.  
  94. const setHeartInput = document.createElement('input');
  95. setHeartInput.id = 'set-heart-input';
  96. setHeartInput.placeholder = 'Enter heart amount';
  97. setHeartInput.type = 'number';
  98. cheatGui.appendChild(setHeartInput);
  99.  
  100. const setHeartButton = document.createElement('button');
  101. setHeartButton.id = 'set-heart-button';
  102. setHeartButton.innerText = 'Set Hearts';
  103. cheatGui.appendChild(setHeartButton);
  104.  
  105. const characterSelect = document.createElement('select');
  106. characterSelect.id = 'character-select';
  107. const heartOptions = ['❤️', '💙', '💚', '💛', '💜']; // Modify as needed
  108. heartOptions.forEach(char => {
  109. const option = document.createElement('option');
  110. option.value = char;
  111. option.innerText = char;
  112. characterSelect.appendChild(option);
  113. });
  114. cheatGui.appendChild(characterSelect);
  115.  
  116. const setCharacterButton = document.createElement('button');
  117. setCharacterButton.id = 'set-character-button';
  118. setCharacterButton.innerText = 'Change Character';
  119. cheatGui.appendChild(setCharacterButton);
  120.  
  121. const buyAnyUpgradeButton = document.createElement('button');
  122. buyAnyUpgradeButton.id = 'buy-any-upgrade-button';
  123. buyAnyUpgradeButton.innerText = 'Buy Any Upgrade';
  124. cheatGui.appendChild(buyAnyUpgradeButton);
  125.  
  126. // Add additional cheats
  127. function addCheatButton(buttonId, buttonText, onClick) {
  128. const button = document.createElement('button');
  129. button.id = buttonId;
  130. button.innerText = buttonText;
  131. button.addEventListener('click', onClick);
  132. cheatGui.appendChild(button);
  133. }
  134.  
  135. // Draggable functionality
  136. function makeDraggable(element) {
  137. let isDragging = false;
  138. let offsetX = 0;
  139. let offsetY = 0;
  140.  
  141. element.addEventListener('mousedown', (e) => {
  142. isDragging = true;
  143. offsetX = e.clientX - element.getBoundingClientRect().left;
  144. offsetY = e.clientY - element.getBoundingClientRect().top;
  145. document.addEventListener('mousemove', onMouseMove);
  146. document.addEventListener('mouseup', onMouseUp);
  147. });
  148.  
  149. function onMouseMove(e) {
  150. if (isDragging) {
  151. const x = e.clientX - offsetX;
  152. const y = e.clientY - offsetY;
  153. element.style.left = `${x}px`;
  154. element.style.top = `${y}px`;
  155. }
  156. }
  157.  
  158. function onMouseUp() {
  159. isDragging = false;
  160. document.removeEventListener('mousemove', onMouseMove);
  161. document.removeEventListener('mouseup', onMouseUp);
  162. }
  163. }
  164.  
  165. makeDraggable(cheatGui);
  166.  
  167. // Game state variables
  168. let heartCount = 0;
  169. let currentHeart = '❤️';
  170.  
  171. // Update heart count display
  172. function updateHeartCount() {
  173. const heartCountElement = document.getElementById('heart-count');
  174. if (heartCountElement) {
  175. heartCountElement.innerText = heartCount;
  176. }
  177. }
  178.  
  179. // Change heart character
  180. function changeHeartCharacter(newHeart) {
  181. currentHeart = newHeart;
  182. const clicker = document.getElementById('clicker');
  183. if (clicker) {
  184. clicker.innerText = currentHeart;
  185. }
  186. }
  187.  
  188. // Apply upgrades
  189. function applyUpgrade() {
  190. const upgrades = document.querySelectorAll('#shop button[id^="buy-upgrade"]');
  191. upgrades.forEach(button => {
  192. const cost = parseInt(button.innerText.replace('Cost: ', '').replace(' Hearts', ''));
  193. if (heartCount >= cost) {
  194. heartCount -= cost;
  195. button.innerText = 'Purchased'; // Mark upgrade as purchased
  196. // Implement specific upgrade logic here
  197. }
  198. });
  199. updateHeartCount();
  200. }
  201.  
  202. // Event handlers
  203. document.getElementById('set-heart-button').addEventListener('click', () => {
  204. const heartAmount = parseInt(document.getElementById('set-heart-input').value);
  205. if (!isNaN(heartAmount)) {
  206. heartCount = heartAmount;
  207. updateHeartCount();
  208. }
  209. });
  210.  
  211. document.getElementById('set-character-button').addEventListener('click', () => {
  212. const selectedCharacter = document.getElementById('character-select').value;
  213. if (selectedCharacter) {
  214. changeHeartCharacter(selectedCharacter);
  215. }
  216. });
  217.  
  218. document.getElementById('buy-any-upgrade-button').addEventListener('click', applyUpgrade);
  219.  
  220. // Add cheat buttons with functionalities
  221. addCheatButton('cheat1', 'Unlock All Upgrades', () => {
  222. document.querySelectorAll('#shop button[id^="buy-upgrade"]').forEach(button => {
  223. button.innerText = 'Purchased'; // Mark as purchased
  224. });
  225. });
  226. addCheatButton('cheat2', 'Add 10,000 Hearts', () => { heartCount += 10000; updateHeartCount(); });
  227. addCheatButton('cheat3', 'Set Hearts to Max', () => { heartCount = Number.MAX_SAFE_INTEGER; updateHeartCount(); });
  228. addCheatButton('cheat4', 'Enable Double Clicks', () => alert('Double clicks enabled!'));
  229. addCheatButton('cheat5', 'Disable Click Limit', () => alert('Click limit disabled!'));
  230. addCheatButton('cheat6', 'Reset Game Progress', () => alert('Game progress reset!'));
  231. addCheatButton('cheat7', 'Add 1 Million Hearts', () => { heartCount += 1000000; updateHeartCount(); });
  232. addCheatButton('cheat8', 'Grant All Achievements', () => alert('All achievements granted!'));
  233. addCheatButton('cheat9', 'Set Heart Multiplier to 10x', () => alert('Heart multiplier set to 10x!'));
  234. addCheatButton('cheat10', 'Unlock VIP Heart Character', () => alert('VIP Heart Character unlocked!'));
  235. addCheatButton('cheat11', 'Instant Auto-Clicker', () => alert('Auto-clicker activated!'));
  236. addCheatButton('cheat12', 'Double Upgrade Speed', () => alert('Upgrade speed doubled!'));
  237. addCheatButton('cheat13', 'Set All Upgrades to Max Level', () => alert('All upgrades set to max level!'));
  238. addCheatButton('cheat14', 'Change Background Color', () => document.body.style.backgroundColor = '#f0f0f0');
  239. addCheatButton('cheat15', 'Enable Infinite Hearts', () => alert('Infinite hearts enabled!'));
  240. addCheatButton('cheat16', 'Grant Extra Lives', () => alert('5 extra lives granted!'));
  241. addCheatButton('cheat17', 'Unlock All Characters', () => alert('All characters unlocked!'));
  242. addCheatButton('cheat18', 'Set Game Speed to Fast', () => alert('Game speed set to fast!'));
  243. addCheatButton('cheat19', 'Apply Random Upgrade', () => alert('Random upgrade applied!'));
  244. addCheatButton('cheat20', 'Reset to Default Settings', () => alert('Game settings reset to default!'));
  245.  
  246. // Restore system excluding cheats
  247. window.addEventListener('beforeunload', (event) => {
  248. const confirmationMessage = 'Are you sure you want to leave? Your progress may be lost!';
  249. event.returnValue = confirmationMessage;
  250. return confirmationMessage;
  251. });
  252.  
  253. // Example of restoring hearts on page reload
  254. function restoreProgress() {
  255. // Restore hearts and other game state from localStorage
  256. const savedHearts = localStorage.getItem('heartCount');
  257. if (savedHearts) {
  258. heartCount = parseInt(savedHearts);
  259. updateHeartCount();
  260. }
  261. }
  262.  
  263. function saveProgress() {
  264. // Save hearts and other game state to localStorage
  265. localStorage.setItem('heartCount', heartCount);
  266. }
  267.  
  268. window.addEventListener('load', restoreProgress);
  269. window.addEventListener('unload', saveProgress);
  270. })();