JavaScript网络执行器

轻松执行JavaScript!

  1. // ==UserScript==
  2. // @name JavaScript Web Executor
  3. // @name:fr Exécuteur Web JavaScript
  4. // @name:es Ejecutor Web de JavaScript
  5. // @name:de JavaScript-Web-Executor
  6. // @name:zh-CN JavaScript网络执行器
  7. // @name:ru JavaScript Веб-Исполнитель
  8. // @description Execute JavaScript with ease!
  9. // @description:fr Exécutez JavaScript facilement!
  10. // @description:es Ejecuta JavaScript con facilidad!
  11. // @description:de Führen Sie JavaScript mühelos aus!
  12. // @description:zh-CN 轻松执行JavaScript!
  13. // @description:ru Выполняйте JavaScript с легкостью!
  14. // @author Luox
  15. // @version 1.6
  16. // @match *://*/*
  17. // @grant none
  18. // @license MIT
  19. // @namespace https://greasyfork.org/users/1365002
  20. // ==/UserScript==
  21.  
  22. (function () {
  23. 'use strict';
  24.  
  25. const css = `
  26. #customJsModal {
  27. position: fixed;
  28. bottom: 20px;
  29. right: 20px;
  30. width: 400px;
  31. background-color: rgba(0, 0, 0, 0.85);
  32. color: white;
  33. padding: 20px;
  34. border-radius: 10px;
  35. box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  36. font-family: Arial, sans-serif;
  37. z-index: 9999;
  38. opacity: 0;
  39. transform: translateY(100px);
  40. transition: all 0.4s ease;
  41. pointer-events: none;
  42. }
  43. #customJsModal.show {
  44. opacity: 1;
  45. transform: translateY(0);
  46. pointer-events: all;
  47. }
  48. #customJsModal textarea {
  49. width: 100%;
  50. height: 150px;
  51. background-color: #333;
  52. color: #fff;
  53. border: none;
  54. padding: 10px;
  55. border-radius: 5px;
  56. font-family: monospace;
  57. resize: none;
  58. margin-bottom: 10px;
  59. }
  60. #customJsModal button {
  61. background-color: #4CAF50;
  62. color: white;
  63. border: none;
  64. padding: 10px 20px;
  65. border-radius: 5px;
  66. cursor: pointer;
  67. transition: background-color 0.3s ease;
  68. }
  69. #customJsModal button:hover {
  70. background-color: #45a049;
  71. }
  72. #customJsModal button.close-btn {
  73. background-color: #f44336;
  74. margin-left: 10px;
  75. }
  76. #customJsModal button.close-btn:hover {
  77. background-color: #d32f2f;
  78. }
  79. #customJsModal button.disable-btn {
  80. background-color: #ff9800;
  81. margin-left: 10px;
  82. }
  83. #customJsModal button.disable-btn:hover {
  84. background-color: #ff5722;
  85. }
  86. #jsExecutorToggle {
  87. position: fixed;
  88. bottom: 20px;
  89. right: 20px;
  90. width: 70px;
  91. height: 70px;
  92. background-color: #f7df1e;
  93. border-radius: 50%;
  94. box-shadow: 0 8px 16px rgba(0, 0, 0, 0.3);
  95. cursor: pointer;
  96. display: flex;
  97. justify-content: center;
  98. align-items: center;
  99. z-index: 9998;
  100. transition: background-color 0.3s ease;
  101. }
  102. #jsExecutorToggle img {
  103. width: 40px;
  104. height: 40px;
  105. pointer-events: none;
  106. }
  107. #jsExecutorToggle:hover {
  108. background-color: #ffeb3b;
  109. }
  110. `;
  111.  
  112. const style = document.createElement('style');
  113. style.textContent = css;
  114. document.head.appendChild(style);
  115.  
  116. const modal = document.createElement('div');
  117. modal.id = 'customJsModal';
  118. modal.innerHTML = `
  119. <textarea id="jsCodeArea" placeholder="Enter your JavaScript code here..."></textarea>
  120. <button id="executeJsBtn">Run</button>
  121. <button class="close-btn">Close</button>
  122. <button class="disable-btn">Disable Script</button>
  123. `;
  124. document.body.appendChild(modal);
  125.  
  126. const toggleButton = document.createElement('button');
  127. toggleButton.id = 'jsExecutorToggle';
  128. toggleButton.innerHTML = `<img src="https://upload.wikimedia.org/wikipedia/commons/6/6a/JavaScript-logo.png" alt="JS Logo">`;
  129. document.body.appendChild(toggleButton);
  130.  
  131. toggleButton.addEventListener('click', () => {
  132. modal.classList.toggle('show');
  133. });
  134.  
  135. document.getElementById('executeJsBtn').addEventListener('click', () => {
  136. const code = document.getElementById('jsCodeArea').value;
  137. try {
  138. new Function(code)();
  139. } catch (e) {
  140. console.error('Error: ' + e.message);
  141. }
  142. });
  143.  
  144. document.querySelector('#customJsModal .close-btn').addEventListener('click', () => {
  145. modal.classList.remove('show');
  146. });
  147.  
  148. document.querySelector('.disable-btn').addEventListener('click', () => {
  149. disableScript();
  150. });
  151.  
  152. let isDragging = false;
  153. let offsetX, offsetY;
  154.  
  155. toggleButton.addEventListener('mousedown', (e) => {
  156. isDragging = true;
  157. offsetX = e.clientX - toggleButton.getBoundingClientRect().left;
  158. offsetY = e.clientY - toggleButton.getBoundingClientRect().top;
  159. toggleButton.style.transition = 'none';
  160. });
  161.  
  162. document.addEventListener('mousemove', (e) => {
  163. if (isDragging) {
  164. toggleButton.style.left = `${e.clientX - offsetX}px`;
  165. toggleButton.style.top = `${e.clientY - offsetY}px`;
  166. }
  167. });
  168.  
  169. document.addEventListener('mouseup', () => {
  170. isDragging = false;
  171. toggleButton.style.transition = 'all 0.4s ease';
  172. });
  173.  
  174. function disableScript() {
  175. toggleButton.remove();
  176. modal.remove();
  177. }
  178. })();