Scratch Custom GUI and Enhancements

Add custom GUI and functionality enhancements to Scratch with Scratch API integration

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

QingJ © 2025

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