Heart Clicker Game Cheat GUI

Add a mini cheat GUI to the Heart Clicker Game and make it draggable

  1. // ==UserScript==
  2. // @name Heart Clicker Game Cheat GUI
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.2
  5. // @description Add a mini cheat GUI to the Heart Clicker Game and make it draggable
  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. }
  28. #cheat-gui button, #cheat-gui input, #cheat-gui select {
  29. margin: 5px 0;
  30. padding: 5px;
  31. font-size: 14px;
  32. border-radius: 5px;
  33. border: 1px solid #ccc;
  34. }
  35. #cheat-gui button {
  36. background-color: #3498db;
  37. color: #fff;
  38. border: none;
  39. cursor: pointer;
  40. transition: background 0.2s ease-in-out;
  41. }
  42. #cheat-gui button:hover {
  43. background-color: #2980b9;
  44. }
  45. `;
  46. document.head.appendChild(style);
  47.  
  48. // Create and add cheat GUI
  49. const cheatGui = document.createElement('div');
  50. cheatGui.id = 'cheat-gui';
  51. document.body.appendChild(cheatGui);
  52.  
  53. const cheatTitle = document.createElement('h2');
  54. cheatTitle.innerText = 'Cheat Console';
  55. cheatGui.appendChild(cheatTitle);
  56.  
  57. const setHeartInput = document.createElement('input');
  58. setHeartInput.id = 'set-heart-input';
  59. setHeartInput.placeholder = 'Enter heart amount';
  60. setHeartInput.type = 'number';
  61. cheatGui.appendChild(setHeartInput);
  62.  
  63. const setHeartButton = document.createElement('button');
  64. setHeartButton.id = 'set-heart-button';
  65. setHeartButton.innerText = 'Set Hearts';
  66. cheatGui.appendChild(setHeartButton);
  67.  
  68. const characterSelect = document.createElement('select');
  69. characterSelect.id = 'character-select';
  70. const heartOptions = ['❤️', '💙', '💚']; // Modify as needed
  71. heartOptions.forEach(char => {
  72. const option = document.createElement('option');
  73. option.value = char;
  74. option.innerText = char;
  75. characterSelect.appendChild(option);
  76. });
  77. cheatGui.appendChild(characterSelect);
  78.  
  79. const setCharacterButton = document.createElement('button');
  80. setCharacterButton.id = 'set-character-button';
  81. setCharacterButton.innerText = 'Change Character';
  82. cheatGui.appendChild(setCharacterButton);
  83.  
  84. const buyAnyUpgradeButton = document.createElement('button');
  85. buyAnyUpgradeButton.id = 'buy-any-upgrade-button';
  86. buyAnyUpgradeButton.innerText = 'Buy Any Upgrade';
  87. cheatGui.appendChild(buyAnyUpgradeButton);
  88.  
  89. // Draggable functionality
  90. function makeDraggable(element) {
  91. let isDragging = false;
  92. let offsetX = 0;
  93. let offsetY = 0;
  94.  
  95. element.addEventListener('mousedown', (e) => {
  96. isDragging = true;
  97. offsetX = e.clientX - element.getBoundingClientRect().left;
  98. offsetY = e.clientY - element.getBoundingClientRect().top;
  99. document.addEventListener('mousemove', onMouseMove);
  100. document.addEventListener('mouseup', onMouseUp);
  101. });
  102.  
  103. function onMouseMove(e) {
  104. if (isDragging) {
  105. const x = e.clientX - offsetX;
  106. const y = e.clientY - offsetY;
  107. element.style.left = `${x}px`;
  108. element.style.top = `${y}px`;
  109. }
  110. }
  111.  
  112. function onMouseUp() {
  113. isDragging = false;
  114. document.removeEventListener('mousemove', onMouseMove);
  115. document.removeEventListener('mouseup', onMouseUp);
  116. }
  117. }
  118.  
  119. makeDraggable(cheatGui);
  120.  
  121. // Game state variables
  122. let heartCount = 0;
  123. let currentHeart = '❤️';
  124.  
  125. // Update heart count display
  126. function updateHeartCount() {
  127. const heartCountElement = document.getElementById('heart-count');
  128. if (heartCountElement) {
  129. heartCountElement.innerText = heartCount;
  130. }
  131. }
  132.  
  133. // Change heart character
  134. function changeHeartCharacter(newHeart) {
  135. currentHeart = newHeart;
  136. const clicker = document.getElementById('clicker');
  137. if (clicker) {
  138. clicker.innerText = currentHeart;
  139. }
  140. }
  141.  
  142. // Apply upgrades
  143. function applyUpgrade() {
  144. const upgrades = document.querySelectorAll('#shop button[id^="buy-upgrade"]');
  145. upgrades.forEach(button => {
  146. const cost = parseInt(button.innerText.replace('Cost: ', '').replace(' Hearts', ''));
  147. if (heartCount >= cost) {
  148. heartCount -= cost;
  149. // Implement specific upgrade logic here
  150. }
  151. });
  152. updateHeartCount();
  153. }
  154.  
  155. // Event handlers
  156. document.getElementById('set-heart-button').addEventListener('click', () => {
  157. const heartAmount = parseInt(document.getElementById('set-heart-input').value);
  158. if (!isNaN(heartAmount)) {
  159. heartCount = heartAmount;
  160. updateHeartCount();
  161. }
  162. });
  163.  
  164. document.getElementById('set-character-button').addEventListener('click', () => {
  165. const selectedCharacter = document.getElementById('character-select').value;
  166. if (selectedCharacter) {
  167. changeHeartCharacter(selectedCharacter);
  168. }
  169. });
  170.  
  171. document.getElementById('buy-any-upgrade-button').addEventListener('click', applyUpgrade);
  172.  
  173. // Function to add a button to the game
  174. function addCheatButton(buttonId, buttonText, onClick) {
  175. const button = document.createElement('button');
  176. button.id = buttonId;
  177. button.innerText = buttonText;
  178. button.addEventListener('click', onClick);
  179. cheatGui.appendChild(button);
  180. }
  181.  
  182. // Optionally add more buttons or functionality as needed
  183. })();