Advanced Scratch Block Customizer

Customize Scratch blocks, create custom blocks, and access advanced settings with a modern UI.

  1. // ==UserScript==
  2. // @name Advanced Scratch Block Customizer
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.3
  5. // @description Customize Scratch blocks, create custom blocks, and access advanced settings with a modern UI.
  6. // @match *://scratch.mit.edu/*
  7. // @grant GM_addStyle
  8. // ==/UserScript==
  9.  
  10. (function() {
  11. 'use strict';
  12.  
  13. // Create the main GUI container
  14. const guiContainer = document.createElement('div');
  15. guiContainer.id = 'scratchCustomizerGui';
  16. document.body.appendChild(guiContainer);
  17.  
  18. // Style the GUI
  19. GM_addStyle(`
  20. #scratchCustomizerGui {
  21. position: fixed;
  22. top: 20px;
  23. right: 20px;
  24. width: 400px;
  25. height: 600px;
  26. background: #ffffff;
  27. border: 1px solid #ddd;
  28. border-radius: 8px;
  29. box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
  30. z-index: 10000;
  31. padding: 20px;
  32. display: none;
  33. overflow-y: auto;
  34. font-family: Arial, sans-serif;
  35. color: #333;
  36. }
  37. #scratchCustomizerGui h2 {
  38. margin-top: 0;
  39. font-size: 24px;
  40. text-align: center;
  41. color: #007bff;
  42. }
  43. #scratchCustomizerGui .gui-section {
  44. margin-bottom: 20px;
  45. border-bottom: 1px solid #eee;
  46. padding-bottom: 15px;
  47. }
  48. #scratchCustomizerGui .gui-section h3 {
  49. font-size: 20px;
  50. color: #333;
  51. }
  52. #scratchCustomizerGui button {
  53. display: block;
  54. width: 100%;
  55. margin: 10px 0;
  56. padding: 12px;
  57. font-size: 16px;
  58. border: none;
  59. border-radius: 5px;
  60. cursor: pointer;
  61. background: #007bff;
  62. color: #fff;
  63. transition: background-color 0.3s;
  64. }
  65. #scratchCustomizerGui button:hover {
  66. background: #0056b3;
  67. }
  68. #scratchCustomizerGui button:active {
  69. background: #004494;
  70. }
  71. #scratchCustomizerGui .color-picker,
  72. #scratchCustomizerGui select,
  73. #scratchCustomizerGui input,
  74. #scratchCustomizerGui textarea {
  75. width: calc(100% - 22px);
  76. padding: 10px;
  77. margin: 10px 0;
  78. border-radius: 4px;
  79. border: 1px solid #ddd;
  80. box-sizing: border-box;
  81. }
  82. #scratchCustomizerGui .custom-block {
  83. display: flex;
  84. align-items: center;
  85. margin-bottom: 10px;
  86. }
  87. #scratchCustomizerGui .custom-block input {
  88. margin-right: 10px;
  89. }
  90. #openScratchCustomizerButton {
  91. position: fixed;
  92. bottom: 20px;
  93. right: 20px;
  94. padding: 10px 15px;
  95. background: #007bff;
  96. color: #fff;
  97. border-radius: 5px;
  98. border: none;
  99. cursor: pointer;
  100. z-index: 10001;
  101. font-size: 16px;
  102. transition: background-color 0.3s;
  103. }
  104. #openScratchCustomizerButton:hover {
  105. background: #0056b3;
  106. }
  107. #openScratchCustomizerButton:active {
  108. background: #004494;
  109. }
  110. #scratchCustomizerGui .theme-option {
  111. display: inline-block;
  112. margin: 0 10px;
  113. padding: 10px;
  114. border-radius: 5px;
  115. cursor: pointer;
  116. text-align: center;
  117. }
  118. #scratchCustomizerGui .theme-option:hover {
  119. background: #f0f0f0;
  120. }
  121. `);
  122.  
  123. // Add an Open button to toggle the GUI
  124. const openButton = document.createElement('button');
  125. openButton.id = 'openScratchCustomizerButton';
  126. openButton.innerText = 'Open Customizer';
  127. document.body.appendChild(openButton);
  128.  
  129. // Event to open/close the GUI
  130. openButton.addEventListener('click', () => {
  131. guiContainer.style.display = guiContainer.style.display === 'none' ? 'block' : 'none';
  132. });
  133.  
  134. // Add close button to GUI
  135. const closeButton = document.createElement('button');
  136. closeButton.innerText = 'Close';
  137. closeButton.addEventListener('click', () => {
  138. guiContainer.style.display = 'none';
  139. });
  140. guiContainer.appendChild(closeButton);
  141.  
  142. // GUI Title
  143. const guiTitle = document.createElement('h2');
  144. guiTitle.innerText = 'Advanced Scratch Customizer';
  145. guiContainer.appendChild(guiTitle);
  146.  
  147. // Section: Block Selection and Modification
  148. const blockSelectionSection = document.createElement('div');
  149. blockSelectionSection.className = 'gui-section';
  150. blockSelectionSection.innerHTML = `
  151. <h3>Select and Modify Block</h3>
  152. <label>Select Block Category:</label>
  153. <select id="blockCategorySelector">
  154. <option value="motion">Motion</option>
  155. <option value="looks">Looks</option>
  156. <option value="sound">Sound</option>
  157. <option value="events">Events</option>
  158. <option value="control">Control</option>
  159. <option value="sensing">Sensing</option>
  160. <option value="operators">Operators</option>
  161. <option value="variables">Variables</option>
  162. <!-- Add more block categories if needed -->
  163. </select>
  164. <label>Select Specific Block:</label>
  165. <select id="specificBlockSelector">
  166. <!-- This will be dynamically populated based on category -->
  167. </select>
  168. <label>Pick a Block Color:</label>
  169. <input type="color" id="blockColorPicker" class="color-picker">
  170. <label>Pick a Text Color:</label>
  171. <input type="color" id="blockTextColorPicker" class="color-picker">
  172. <label>Pick a Block Background Color:</label>
  173. <input type="color" id="blockBgColorPicker" class="color-picker">
  174. <button id="applyBlockColorButton">Apply Changes</button>
  175. `;
  176. guiContainer.appendChild(blockSelectionSection);
  177.  
  178. // Section: Custom Block Editor
  179. const customBlockSection = document.createElement('div');
  180. customBlockSection.className = 'gui-section';
  181. customBlockSection.innerHTML = `
  182. <h3>Custom Block Editor</h3>
  183. <button id="createCustomBlockButton">Create New Block</button>
  184. <button id="modifyBlockFunctionButton">Modify Block Functions</button>
  185. <div id="customBlockEditor" class="gui-section" style="display: none;">
  186. <h4>Custom Block Editor</h4>
  187. <label>Block Name:</label>
  188. <input type="text" id="customBlockName" placeholder="Enter block name">
  189. <label>Block Color:</label>
  190. <input type="color" id="customBlockColor" class="color-picker">
  191. <label>Block Function:</label>
  192. <textarea id="customBlockFunction" rows="4" placeholder="Enter block function code"></textarea>
  193. <button id="saveCustomBlockButton">Save Block</button>
  194. </div>
  195. `;
  196. guiContainer.appendChild(customBlockSection);
  197.  
  198. // Section: Theme Chooser
  199. const themeSection = document.createElement('div');
  200. themeSection.className = 'gui-section';
  201. themeSection.innerHTML = `
  202. <h3>Theme Chooser</h3>
  203. <div id="themeOptions">
  204. <div class="theme-option" id="defaultTheme">Default</div>
  205. <div class="theme-option" id="darkTheme">Dark</div>
  206. <div class="theme-option" id="cupcakeTheme">Cupcake</div>
  207. <div class="theme-option" id="moonTheme">Moon</div>
  208. <div class="theme-option" id="sunTheme">Sun</div>
  209. </div>
  210. `;
  211. guiContainer.appendChild(themeSection);
  212.  
  213. // Section: Custom Settings
  214. const settingsSection = document.createElement('div');
  215. settingsSection.className = 'gui-section';
  216. settingsSection.innerHTML = `
  217. <h3>Custom Settings</h3>
  218. <button id="openSettingsButton">Open Settings</button>
  219. `;
  220. guiContainer.appendChild(settingsSection);
  221.  
  222. // Event Listener for Block Category Selection
  223. document.getElementById('blockCategorySelector').addEventListener('change', function() {
  224. const category = this.value;
  225. populateSpecificBlocks(category);
  226. });
  227.  
  228. // Populate specific blocks based on the selected category
  229. function populateSpecificBlocks(category) {
  230. const blockSelector = document.getElementById('specificBlockSelector');
  231. blockSelector.innerHTML = ''; // Clear existing options
  232.  
  233. // Define blocks based on categories
  234. const blocks = {
  235. motion: ['Move 10 Steps', 'Turn Right', 'Turn Left'],
  236. looks: ['Say Hello', 'Think Hmm', 'Switch Costume'],
  237. sound: ['Play Sound', 'Stop All Sounds'],
  238. events: ['When Flag Clicked', 'When Key Pressed'],
  239. control: ['Wait 1 Sec', 'Repeat 10 Times'],
  240. sensing: ['Ask and Wait', 'Touching Color'],
  241. operators: ['Pick Random 1 to 10', 'Join', 'Letter of'],
  242. variables: ['Set Variable', 'Change Variable']
  243. };
  244.  
  245. blocks[category].forEach(block => {
  246. const option = document.createElement('option');
  247. option.value = block;
  248. option.text = block;
  249. blockSelector.appendChild(option);
  250. });
  251. }
  252.  
  253. // Event Listener for Apply Block Color Button
  254. document.getElementById('applyBlockColorButton').addEventListener('click', () => {
  255. const blockType = document.getElementById('specificBlockSelector').value;
  256. const blockColor = document.getElementById('blockColorPicker').value;
  257. const textColor = document.getElementById('blockTextColorPicker').value;
  258. const bgColor = document.getElementById('blockBgColorPicker').value;
  259.  
  260. applyBlockStyles(blockType, blockColor, textColor, bgColor);
  261. });
  262.  
  263. // Event Listener for Create Custom Block Button
  264. document.getElementById('createCustomBlockButton').addEventListener('click', () => {
  265. document.getElementById('customBlockEditor').style.display = 'block';
  266. });
  267.  
  268. // Event Listener for Modify Block Function Button
  269. document.getElementById('modifyBlockFunctionButton').addEventListener('click', () => {
  270. document.getElementById('customBlockEditor').style.display = 'block';
  271. });
  272.  
  273. // Event Listener for Save Custom Block Button
  274. document.getElementById('saveCustomBlockButton').addEventListener('click', () => {
  275. const name = document.getElementById('customBlockName').value;
  276. const color = document.getElementById('customBlockColor').value;
  277. const functionCode = document.getElementById('customBlockFunction').value;
  278.  
  279. // Save the custom block (to be implemented)
  280. alert(`Saved custom block: ${name}\nColor: ${color}\nFunction: ${functionCode}`);
  281. });
  282.  
  283. // Event Listener for Apply Theme Button
  284. document.querySelectorAll('.theme-option').forEach(button => {
  285. button.addEventListener('click', () => {
  286. const theme = button.id.replace('Theme', '');
  287. applyTheme(theme);
  288. });
  289. });
  290.  
  291. // Event Listener for Open Settings Button
  292. document.getElementById('openSettingsButton').addEventListener('click', () => {
  293. openCustomSettings();
  294. });
  295.  
  296. // Function to apply block styles
  297. function applyBlockStyles(blockType, blockColor, textColor, bgColor) {
  298. alert(`Applying styles to block: ${blockType}\nColor: ${blockColor}\nText Color: ${textColor}\nBackground Color: ${bgColor}`);
  299. // Implement style application to blocks here
  300. }
  301.  
  302. // Function to apply a theme
  303. function applyTheme(theme) {
  304. alert(`Applying theme: ${theme}`);
  305. // Implement theme application to the Scratch website here
  306. }
  307.  
  308. // Function to open custom settings (To be implemented)
  309. function openCustomSettings() {
  310. alert('Custom Settings not yet implemented.');
  311. }
  312. })();

QingJ © 2025

镜像随时可能失效,请加Q群300939539或关注我们的公众号极客氢云获取最新地址