CracksHash Magnet Getter with Popup Blocker

Adds a floating button that gets the magnet link when pressed and blocks pop-up windows

  1. // ==UserScript==
  2. // @name CracksHash Magnet Getter with Popup Blocker
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.7
  5. // @description Adds a floating button that gets the magnet link when pressed and blocks pop-up windows
  6. // @author ThatDudeJBob
  7. // @match *://crackshash.com/*
  8. // @grant none
  9. // @license MIT
  10. // ==/UserScript==
  11.  
  12. (function() {
  13. 'use strict';
  14.  
  15. // Configuration
  16. const buttonConfig = {
  17. text: localStorage.getItem('buttonText') || 'Click Magnet',
  18. backgroundColor: localStorage.getItem('buttonBgColor') || '#007bff',
  19. textColor: 'white',
  20. initialTop: localStorage.getItem('buttonTop') || '10px',
  21. initialRight: localStorage.getItem('buttonRight') || '10px'
  22. };
  23.  
  24. // Helper function to create and style elements
  25. function createElement(type, styles, textContent = '') {
  26. const element = document.createElement(type);
  27. Object.assign(element.style, styles);
  28. element.textContent = textContent;
  29. return element;
  30. }
  31.  
  32. // Function to show overlay warning
  33. function showOverlayWarning(message, type) {
  34. const overlay = createElement('div', {
  35. position: 'fixed',
  36. top: '10px',
  37. left: '50%',
  38. transform: 'translateX(-50%)',
  39. backgroundColor: type === 'error' ? 'rgba(245, 0, 0, 0.5)' : 'rgba(0, 0, 0, 0.5)',
  40. color: 'white',
  41. padding: '10px',
  42. borderRadius: '5px',
  43. zIndex: '1000',
  44. transition: 'opacity 1s',
  45. opacity: '1'
  46. }, message);
  47. document.body.appendChild(overlay);
  48.  
  49. setTimeout(() => {
  50. overlay.style.opacity = '0';
  51. setTimeout(() => document.body.removeChild(overlay), 1000);
  52. }, 2000);
  53. }
  54.  
  55. // Function to toggle settings menu visibility
  56. function toggleSettingsMenu() {
  57. settingsMenu.style.display = settingsMenu.style.display === 'none' ? 'block' : 'none';
  58. }
  59.  
  60. // Save settings
  61. function saveSettings() {
  62. localStorage.setItem('buttonText', buttonTextInput.value);
  63. localStorage.setItem('buttonBgColor', buttonBgColorInput.value);
  64. localStorage.setItem('buttonTop', buttonTopInput.value + 'px');
  65. localStorage.setItem('buttonRight', buttonRightInput.value + 'px');
  66. button.innerText = buttonTextInput.value;
  67. button.style.backgroundColor = buttonBgColorInput.value;
  68. button.style.top = buttonTopInput.value + 'px';
  69. button.style.right = buttonRightInput.value + 'px';
  70. settingsMenu.style.display = 'none';
  71. }
  72.  
  73. // Block pop-up windows, except for settings menu interactions
  74. function preventPopup(e) {
  75. if (e.target.tagName === 'A' && (e.target.href.startsWith('magnet:') || new URL(e.target.href).hostname === window.location.hostname)) {
  76. return;
  77. }
  78.  
  79. if (settingsMenu.contains(e.target) || e.target === settingsButton) {
  80. return;
  81. }
  82.  
  83. e.preventDefault();
  84. }
  85.  
  86. // Create the floating button
  87. const button = createElement('button', {
  88. position: 'fixed',
  89. top: buttonConfig.initialTop,
  90. right: buttonConfig.initialRight,
  91. zIndex: '1000',
  92. backgroundColor: buttonConfig.backgroundColor,
  93. color: buttonConfig.textColor,
  94. border: 'none',
  95. padding: '10px',
  96. borderRadius: '5px',
  97. cursor: 'pointer',
  98. width: 'auto',
  99. whiteSpace: 'nowrap'
  100. }, buttonConfig.text);
  101. document.body.appendChild(button);
  102.  
  103. // Create the settings button
  104. const settingsButton = createElement('button', {
  105. position: 'fixed',
  106. top: '10px',
  107. right: '50px', // Adjusted to avoid overlap
  108. zIndex: '1000',
  109. backgroundColor: '#555',
  110. color: 'white',
  111. border: 'none',
  112. padding: '10px',
  113. borderRadius: '5px',
  114. cursor: 'pointer',
  115. width: 'auto',
  116. whiteSpace: 'nowrap'
  117. }, '?');
  118. document.body.appendChild(settingsButton);
  119.  
  120. // Create the settings menu
  121. const settingsMenu = createElement('div', {
  122. position: 'fixed',
  123. top: '40px',
  124. right: '10px',
  125. zIndex: '1000',
  126. backgroundColor: '#333',
  127. color: 'white',
  128. padding: '10px',
  129. borderRadius: '5px',
  130. display: 'none'
  131. });
  132. document.body.appendChild(settingsMenu);
  133.  
  134. const buttonTextInput = createElement('input', { display: 'block', marginBottom: '10px' });
  135. buttonTextInput.type = 'text';
  136. buttonTextInput.placeholder = 'Button Text';
  137. buttonTextInput.value = buttonConfig.text;
  138. settingsMenu.appendChild(buttonTextInput);
  139.  
  140. const buttonBgColorInput = createElement('input', { display: 'block', marginBottom: '10px' });
  141. buttonBgColorInput.type = 'color';
  142. buttonBgColorInput.value = buttonConfig.backgroundColor;
  143. settingsMenu.appendChild(buttonBgColorInput);
  144.  
  145. const buttonTopInput = createElement('input', { display: 'block', marginBottom: '10px' });
  146. buttonTopInput.type = 'number';
  147. buttonTopInput.placeholder = 'Top Position (px)';
  148. buttonTopInput.value = parseInt(buttonConfig.initialTop, 10);
  149. settingsMenu.appendChild(buttonTopInput);
  150.  
  151. const buttonRightInput = createElement('input', { display: 'block', marginBottom: '10px' });
  152. buttonRightInput.type = 'number';
  153. buttonRightInput.placeholder = 'Right Position (px)';
  154. buttonRightInput.value = parseInt(buttonConfig.initialRight, 10);
  155. settingsMenu.appendChild(buttonRightInput);
  156.  
  157. const saveButton = createElement('button', {
  158. marginTop: '10px',
  159. backgroundColor: '#007bff',
  160. color: 'white',
  161. border: 'none',
  162. padding: '5px',
  163. borderRadius: '5px',
  164. cursor: 'pointer'
  165. }, 'Save');
  166. settingsMenu.appendChild(saveButton);
  167.  
  168. settingsButton.addEventListener('click', toggleSettingsMenu);
  169. saveButton.addEventListener('click', saveSettings);
  170.  
  171. document.addEventListener('click', (event) => {
  172. if (!settingsMenu.contains(event.target) && event.target !== settingsButton) {
  173. settingsMenu.style.display = 'none';
  174. }
  175. });
  176.  
  177. // Add click event to the button
  178. button.addEventListener('click', () => {
  179. const magnetLink = document.querySelector('a[href^="magnet:"]');
  180. if (magnetLink) {
  181. const originalBeforeUnload = window.onbeforeunload; // Backup the original onbeforeunload handler
  182. window.onbeforeunload = null; // Allow navigation for this action
  183. magnetLink.click();
  184. window.onbeforeunload = originalBeforeUnload; // Restore the original handler
  185. } else {
  186. showOverlayWarning('No magnet link found on this page.', 'error');
  187. }
  188. });
  189.  
  190. // Override window.open to detect blocked pop-ups
  191. const originalWindowOpen = window.open;
  192. window.open = function(url, name, specs) {
  193. const newWindow = originalWindowOpen(url, name, specs);
  194. if (!newWindow || newWindow.closed || typeof newWindow.closed === 'undefined') {
  195. showOverlayWarning('Blocked a pop-up window.', 'error');
  196. }
  197. return newWindow;
  198. };
  199.  
  200. window.addEventListener('beforeunload', preventPopup);
  201. window.addEventListener('unload', preventPopup);
  202. document.addEventListener('click', preventPopup);
  203. })();