Scratch Custom GUI and Enhancements

Add custom GUI and functionality enhancements to Scratch

  1. // ==UserScript==
  2. // @name Scratch Custom GUI and Enhancements
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1
  5. // @description Add custom GUI and functionality enhancements to Scratch
  6. // @match https://scratch.mit.edu/*
  7. // @grant GM_addStyle
  8. // @run-at document-end
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. // Function to create a page
  15. function createPage(id, title, content) {
  16. const page = document.createElement('div');
  17. page.id = id;
  18. page.style.display = 'none';
  19. page.style.position = 'fixed';
  20. page.style.top = '10px';
  21. page.style.left = '10px';
  22. page.style.backgroundColor = '#ffffff';
  23. page.style.border = '1px solid #ddd';
  24. page.style.padding = '10px';
  25. page.style.zIndex = 1000;
  26. page.style.borderRadius = '5px';
  27. page.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.3)';
  28. page.style.fontFamily = 'Arial, sans-serif';
  29. page.innerHTML = `<h2>${title}</h2>${content}<button onclick="closePage('${id}')">X</button>`;
  30. document.body.appendChild(page);
  31. }
  32.  
  33. // Function to create the main GUI
  34. function createMainGUI() {
  35. const mainGUI = document.createElement('div');
  36. mainGUI.id = 'main-gui';
  37. mainGUI.style.position = 'fixed';
  38. mainGUI.style.top = '10px';
  39. mainGUI.style.right = '10px';
  40. mainGUI.style.backgroundColor = '#ffffff';
  41. mainGUI.style.border = '1px solid #ddd';
  42. mainGUI.style.padding = '10px';
  43. mainGUI.style.zIndex = 1000;
  44. mainGUI.style.borderRadius = '5px';
  45. mainGUI.style.boxShadow = '0 0 10px rgba(0, 0, 0, 0.3)';
  46. mainGUI.style.fontFamily = 'Arial, sans-serif';
  47. document.body.appendChild(mainGUI);
  48.  
  49. const pages = ['block-editor', 'block-color-changer', 'custom-block-maker', 'theme-changer', 'modifiers'];
  50.  
  51. pages.forEach(pageId => {
  52. const button = document.createElement('button');
  53. button.innerText = pageId.replace(/-/g, ' ').toUpperCase();
  54. button.style.margin = '5px';
  55. button.style.padding = '5px 10px';
  56. button.style.border = 'none';
  57. button.style.borderRadius = '3px';
  58. button.style.cursor = 'pointer';
  59. button.style.backgroundColor = '#007bff';
  60. button.style.color = '#fff';
  61. button.onclick = function() {
  62. pages.forEach(id => {
  63. document.getElementById(id).style.display = (id === pageId) ? 'block' : 'none';
  64. });
  65. };
  66. mainGUI.appendChild(button);
  67. });
  68.  
  69. const closeButton = document.createElement('button');
  70. closeButton.innerText = 'Close GUI';
  71. closeButton.style.margin = '5px';
  72. closeButton.style.padding = '5px 10px';
  73. closeButton.style.border = 'none';
  74. closeButton.style.borderRadius = '3px';
  75. closeButton.style.cursor = 'pointer';
  76. closeButton.style.backgroundColor = '#dc3545';
  77. closeButton.style.color = '#fff';
  78. closeButton.onclick = function() {
  79. mainGUI.style.display = (mainGUI.style.display === 'none') ? 'block' : 'none';
  80. };
  81. mainGUI.appendChild(closeButton);
  82. }
  83.  
  84. // Function to create the Block Editor page
  85. function createBlockEditorPage() {
  86. createPage('block-editor', 'Block Editor', `
  87. <label for="block-name">Block Name:</label>
  88. <input type="text" id="block-name" />
  89. <br/><br/>
  90. <label for="block-color">Block Color:</label>
  91. <input type="color" id="block-color" />
  92. <br/><br/>
  93. <label for="block-inside-color">Inside Color:</label>
  94. <input type="color" id="block-inside-color" />
  95. <br/><br/>
  96. <button onclick="createCustomBlock()">Create Custom Block</button>
  97. `);
  98.  
  99. window.createCustomBlock = function() {
  100. const blockName = document.getElementById('block-name').value;
  101. const blockColor = document.getElementById('block-color').value;
  102. const blockInsideColor = document.getElementById('block-inside-color').value;
  103. console.log('Creating custom block:', blockName, blockColor, blockInsideColor);
  104. // Implement logic to create a custom block in Scratch
  105. // Use Scratch API or tools to add the block to the Scratch project
  106. };
  107. }
  108.  
  109. // Function to create the Block Color Changer page
  110. function createBlockColorChangerPage() {
  111. createPage('block-color-changer', 'Block Color Changer', `
  112. <label for="block-select-color">Select Block:</label>
  113. <select id="block-select-color">
  114. <!-- Populate with block options -->
  115. </select>
  116. <br/><br/>
  117. <label for="block-new-color">New Block Color:</label>
  118. <input type="color" id="block-new-color" />
  119. <br/><br/>
  120. <button onclick="changeBlockColor()">Change Color</button>
  121. `);
  122.  
  123. window.changeBlockColor = function() {
  124. const block = document.getElementById('block-select-color').value;
  125. const newColor = document.getElementById('block-new-color').value;
  126. console.log('Changing block color to:', newColor);
  127. // Implement logic to change the color of the selected block
  128. // Use Scratch API or tools to modify the color of the block in the Scratch project
  129. };
  130. }
  131.  
  132. // Function to create the Custom Block Maker page
  133. function createCustomBlockMakerPage() {
  134. createPage('custom-block-maker', 'Custom Block Maker', `
  135. <label for="block-name-new">Block Name:</label>
  136. <input type="text" id="block-name-new" />
  137. <br/><br/>
  138. <label for="block-color-new">Block Color:</label>
  139. <input type="color" id="block-color-new" />
  140. <br/><br/>
  141. <label for="block-inside-color-new">Inside Color:</label>
  142. <input type="color" id="block-inside-color-new" />
  143. <br/><br/>
  144. <button onclick="createNewCustomBlock()">Create Block</button>
  145. `);
  146.  
  147. window.createNewCustomBlock = function() {
  148. const blockName = document.getElementById('block-name-new').value;
  149. const blockColor = document.getElementById('block-color-new').value;
  150. const blockInsideColor = document.getElementById('block-inside-color-new').value;
  151. console.log('Creating new custom block:', blockName, blockColor, blockInsideColor);
  152. // Implement logic to create a new custom block with the specified properties
  153. // Integrate with Scratch API or tools to add this block to Scratch
  154. };
  155. }
  156.  
  157. // Function to create the Theme Changer page
  158. function createThemeChangerPage() {
  159. createPage('theme-changer', 'Theme Changer', `
  160. <label for="theme-select">Select Theme:</label>
  161. <select id="theme-select">
  162. <option value="cupcake">Cupcake</option>
  163. <option value="candy">Candy</option>
  164. <option value="dark">Dark</option>
  165. <option value="marshmallow">Marshmallow</option>
  166. <option value="bloody">Bloody</option>
  167. <option value="image">Image</option>
  168. </select>
  169. <br/><br/>
  170. <label for="theme-image-url" id="image-url-label" style="display: none;">Image URL:</label>
  171. <input type="text" id="theme-image-url" style="display: none;" />
  172. <br/><br/>
  173. <button onclick="applyTheme()">Apply Theme</button>
  174. `);
  175.  
  176. window.applyTheme = function() {
  177. const theme = document.getElementById('theme-select').value;
  178. const imageUrl = document.getElementById('theme-image-url').value;
  179.  
  180. const themes = {
  181. 'cupcake': `
  182. body { background-color: #fbe8e8; color: #6a1b29; }
  183. .stage { background: #fcdada; }
  184. .backdrop { background: #f6a7b1; }
  185. `,
  186. 'candy': `
  187. body { background-color: #f7e7e0; color: #ff4f5a; }
  188. .stage { background: #e5c7c3; }
  189. .backdrop { background: #fddfdd; }
  190. `,
  191. 'dark': `
  192. body { background-color: #333; color: #f5f5f5; }
  193. .stage { background: #555; }
  194. .backdrop { background: #444; }
  195. `,
  196. 'marshmallow': `
  197. body { background-color: #fff; color: #000; }
  198. .stage { background: #f5f5f5; }
  199. .backdrop { background: #e0e0e0; }
  200. `,
  201. 'bloody': `
  202. body { background-color: #3e0d0d; color: #f5f5f5; }
  203. .stage { background: #6a0b0b; }
  204. .backdrop { background: #9e0f0f; }
  205. `,
  206. 'image': `
  207. body { background-image: url('${imageUrl}'); color: #ffffff; }
  208. .stage { background: rgba(0, 0, 0, 0.5); }
  209. .backdrop { background: rgba(0, 0, 0, 0.5); }
  210. `
  211. };
  212.  
  213. if (theme === 'image') {
  214. document.getElementById('image-url-label').style.display = 'block';
  215. document.getElementById('theme-image-url').style.display = 'block';
  216. } else {
  217. document.getElementById('image-url-label').style.display = 'none';
  218. document.getElementById('theme-image-url').style.display = 'none';
  219. applyThemeStyles(themes[theme]);
  220. }
  221. };
  222.  
  223. function applyThemeStyles(css) {
  224. let existingStyle = document.getElementById('theme-style');
  225. if (existingStyle) {
  226. existingStyle.remove();
  227. }
  228. const style = document.createElement('style');
  229. style.id = 'theme-style';
  230. style.innerHTML = css;
  231. document.head.appendChild(style);
  232. }
  233. }
  234.  
  235. // Function to create the Modifiers tab page
  236. function createModifiersPage() {
  237. createPage('modifiers', 'Modifiers', `
  238. <label for="modifier-name">Modifier Name:</label>
  239. <input type="text" id="modifier-name" />
  240. <br/><br/>
  241. <button onclick="addModifier()">Add Modifier</button>
  242. <br/><br/>
  243. <div id="modifiers-list"></div>
  244. `);
  245.  
  246. window.addModifier = function() {
  247. const modifierName = document.getElementById('modifier-name').value;
  248. console.log('Adding modifier:', modifierName);
  249. // Implement logic to add a modifier to Scratch blocks
  250. // This could involve creating new functions or altering existing ones
  251. const modifiersList = document.getElementById('modifiers-list');
  252. const modifierItem = document.createElement('div');
  253. modifierItem.textContent = modifierName;
  254. modifiersList.appendChild(modifierItem);
  255. };
  256. }
  257.  
  258. // Initialize GUI and pages
  259. createMainGUI();
  260. createBlockEditorPage();
  261. createBlockColorChangerPage();
  262. createCustomBlockMakerPage();
  263. createThemeChangerPage();
  264. createModifiersPage();
  265. })();

QingJ © 2025

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