Spectrum Executor GUI

A script executor with a draggable GUI that executes code safely on any website

  1. // ==UserScript==
  2. // @name Spectrum Executor GUI
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.5
  5. // @description A script executor with a draggable GUI that executes code safely on any website
  6. // @author Your Name
  7. // @match *://*/*
  8. // @grant GM_addStyle
  9. // @grant GM_getResourceText
  10. // @grant GM_xmlhttpRequest
  11. // @grant GM_openInTab
  12. // @grant GM_registerMenuCommand
  13. // @grant GM_setClipboard
  14. // @grant GM_getClipboard
  15. // ==/UserScript==
  16.  
  17. (function() {
  18. 'use strict';
  19.  
  20. // Create the GUI container
  21. const guiContainer = document.createElement('div');
  22. guiContainer.style.position = 'fixed';
  23. guiContainer.style.top = '100px';
  24. guiContainer.style.left = '100px';
  25. guiContainer.style.width = '420px'; // Width adjusted for proper alignment
  26. guiContainer.style.backgroundColor = '#c7c7c7';
  27. guiContainer.style.borderRadius = '15px';
  28. guiContainer.style.padding = '20px';
  29. guiContainer.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.1)';
  30. guiContainer.style.zIndex = '9999';
  31. guiContainer.style.cursor = 'move';
  32. document.body.appendChild(guiContainer);
  33.  
  34. // Create the text area for code input
  35. const codeBox = document.createElement('textarea');
  36. codeBox.style.width = '95.4%';
  37. codeBox.style.height = '150px';
  38. codeBox.style.borderRadius = '10px';
  39. codeBox.style.border = 'none';
  40. codeBox.style.padding = '10px';
  41. codeBox.style.fontSize = '14px';
  42. codeBox.style.resize = 'none';
  43. codeBox.style.backgroundColor = '#f0f0f0';
  44. codeBox.style.outline = 'none';
  45. codeBox.style.overflowY = 'auto'; // Enable vertical scrolling
  46. codeBox.style.whiteSpace = 'pre-wrap'; // Preserve line breaks and wrap long lines
  47. guiContainer.appendChild(codeBox);
  48.  
  49. // Create the button container
  50. const buttonContainer = document.createElement('div');
  51. buttonContainer.style.display = 'flex';
  52. buttonContainer.style.flexWrap = 'wrap'; // Allow buttons to wrap on small screens
  53. buttonContainer.style.marginTop = '15px';
  54. guiContainer.appendChild(buttonContainer);
  55.  
  56. // Create a common button style
  57. const buttonStyle = {
  58. border: 'none',
  59. borderRadius: '10px',
  60. padding: '10px 20px',
  61. backgroundColor: '#ffffff',
  62. fontSize: '14px',
  63. fontWeight: 'bold', // Make text bold
  64. cursor: 'pointer',
  65. boxShadow: '0 0 5px rgba(0, 0, 0, 0.1)',
  66. flex: '1',
  67. margin: '0 5px'
  68. };
  69.  
  70. // Create the Inject button
  71. const injectBtn = document.createElement('button');
  72. injectBtn.innerText = 'Inject';
  73. Object.assign(injectBtn.style, buttonStyle);
  74. buttonContainer.appendChild(injectBtn);
  75.  
  76. // Create the Execute button
  77. const executeBtn = document.createElement('button');
  78. executeBtn.innerText = 'Execute';
  79. Object.assign(executeBtn.style, buttonStyle);
  80. executeBtn.disabled = true;
  81. buttonContainer.appendChild(executeBtn);
  82.  
  83. // Create the Clear button
  84. const clearBtn = document.createElement('button');
  85. clearBtn.innerText = 'Clear';
  86. Object.assign(clearBtn.style, buttonStyle);
  87. clearBtn.disabled = true;
  88. buttonContainer.appendChild(clearBtn);
  89.  
  90. // Create the Copy button
  91. const copyBtn = document.createElement('button');
  92. copyBtn.innerText = 'Copy';
  93. Object.assign(copyBtn.style, buttonStyle);
  94. copyBtn.disabled = true; // Initially disabled
  95. buttonContainer.appendChild(copyBtn);
  96.  
  97. // Create the Paste button
  98. const pasteBtn = document.createElement('button');
  99. pasteBtn.innerText = 'Paste';
  100. Object.assign(pasteBtn.style, buttonStyle);
  101. pasteBtn.disabled = true; // Initially disabled
  102. buttonContainer.appendChild(pasteBtn);
  103.  
  104. let isInjected = false;
  105.  
  106. // Inject Button Logic
  107. injectBtn.addEventListener('click', () => {
  108. isInjected = true;
  109. executeBtn.disabled = false;
  110. clearBtn.disabled = false;
  111. copyBtn.disabled = false; // Enable Copy button
  112. pasteBtn.disabled = false; // Enable Paste button
  113. alert('Injected successfully!');
  114. });
  115.  
  116. // Execute Button Logic
  117. executeBtn.addEventListener('click', () => {
  118. if (isInjected) {
  119. try {
  120. // Use Function constructor for safe execution
  121. new Function(codeBox.value)();
  122. alert('Script executed successfully!');
  123. } catch (error) {
  124. alert('Error executing script: ' + error.message);
  125. }
  126. } else {
  127. alert('Please inject first!');
  128. }
  129. });
  130.  
  131. // Clear Button Logic
  132. clearBtn.addEventListener('click', () => {
  133. if (isInjected) {
  134. codeBox.value = '';
  135. } else {
  136. alert('Please inject first!');
  137. }
  138. });
  139.  
  140. // Copy Button Logic
  141. copyBtn.addEventListener('click', () => {
  142. if (isInjected) {
  143. codeBox.select();
  144. document.execCommand('copy');
  145. alert('Copied to clipboard!');
  146. } else {
  147. alert('Please inject first!');
  148. }
  149. });
  150.  
  151. // Paste Button Logic
  152. pasteBtn.addEventListener('click', async () => {
  153. if (isInjected) {
  154. try {
  155. const clipboardText = await navigator.clipboard.readText();
  156. codeBox.value = clipboardText;
  157. alert('Pasted from clipboard!');
  158. } catch (error) {
  159. alert('Failed to paste from clipboard: ' + error.message);
  160. }
  161. } else {
  162. alert('Please inject first!');
  163. }
  164. });
  165.  
  166. // Dragging functionality for the GUI
  167. let isDragging = false;
  168. let offsetX, offsetY;
  169.  
  170. guiContainer.addEventListener('mousedown', function(e) {
  171. isDragging = true;
  172. offsetX = e.clientX - parseInt(window.getComputedStyle(guiContainer).left);
  173. offsetY = e.clientY - parseInt(window.getComputedStyle(guiContainer).top);
  174. guiContainer.style.cursor = 'grabbing';
  175. });
  176.  
  177. document.addEventListener('mousemove', function(e) {
  178. if (isDragging) {
  179. guiContainer.style.left = e.clientX - offsetX + 'px';
  180. guiContainer.style.top = e.clientY - offsetY + 'px';
  181. }
  182. });
  183.  
  184. document.addEventListener('mouseup', function() {
  185. isDragging = false;
  186. guiContainer.style.cursor = 'move';
  187. });
  188.  
  189. // Make the GUI draggable on touch devices as well
  190. guiContainer.addEventListener('touchstart', function(e) {
  191. isDragging = true;
  192. const touch = e.touches[0];
  193. offsetX = touch.clientX - parseInt(window.getComputedStyle(guiContainer).left);
  194. offsetY = touch.clientY - parseInt(window.getComputedStyle(guiContainer).top);
  195. guiContainer.style.cursor = 'grabbing';
  196. });
  197.  
  198. document.addEventListener('touchmove', function(e) {
  199. if (isDragging) {
  200. const touch = e.touches[0];
  201. guiContainer.style.left = touch.clientX - offsetX + 'px';
  202. guiContainer.style.top = touch.clientY - offsetY + 'px';
  203. }
  204. });
  205.  
  206. document.addEventListener('touchend', function() {
  207. isDragging = false;
  208. guiContainer.style.cursor = 'move';
  209. });
  210.  
  211. })();