Scratch Custom Block Injector

Injects a custom Scratch block, keeps it within the code box, and crashes the project

  1. // ==UserScript==
  2. // @name Scratch Custom Block Injector
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.1
  5. // @description Injects a custom Scratch block, keeps it within the code box, and crashes the project
  6. // @author You
  7. // @match *://scratch.mit.edu/projects/editor/*
  8. // @grant none
  9. // ==/UserScript==
  10.  
  11. (function() {
  12. 'use strict';
  13.  
  14. function injectBlockImage() {
  15. const workspace = document.querySelector(".blocklyWorkspace");
  16. if (!workspace) return;
  17.  
  18. let blockImage = document.createElement("img");
  19. blockImage.src = "https://i.ibb.co/MD0wbSkd/Untitled502-20250203231330.png";
  20. blockImage.style.position = "absolute";
  21. blockImage.style.left = "200px";
  22. blockImage.style.top = "150px";
  23. blockImage.style.width = "120px";
  24. blockImage.style.height = "40px";
  25. blockImage.style.cursor = "grab";
  26. blockImage.draggable = true;
  27. blockImage.style.zIndex = "1000";
  28.  
  29. let offsetX, offsetY;
  30. function moveBlock(e) {
  31. const codeBox = workspace.getBoundingClientRect();
  32. let newX = e.clientX - offsetX;
  33. let newY = e.clientY - offsetY;
  34. // Keep within code box boundaries
  35. if (newX < codeBox.left) newX = codeBox.left;
  36. if (newX + blockImage.clientWidth > codeBox.right) newX = codeBox.right - blockImage.clientWidth;
  37. if (newY < codeBox.top) newY = codeBox.top;
  38. if (newY + blockImage.clientHeight > codeBox.bottom) newY = codeBox.bottom - blockImage.clientHeight;
  39. blockImage.style.left = `${newX}px`;
  40. blockImage.style.top = `${newY}px`;
  41. }
  42.  
  43. blockImage.addEventListener("mousedown", (e) => {
  44. offsetX = e.clientX - blockImage.getBoundingClientRect().left;
  45. offsetY = e.clientY - blockImage.getBoundingClientRect().top;
  46. document.addEventListener("mousemove", moveBlock);
  47. document.addEventListener("mouseup", () => {
  48. document.removeEventListener("mousemove", moveBlock);
  49. });
  50. });
  51.  
  52. workspace.appendChild(blockImage);
  53. }
  54.  
  55. function crashAndClose() {
  56. const runButton = document.querySelector(".green-flag");
  57. if (runButton) {
  58. runButton.addEventListener("click", () => {
  59. setTimeout(() => {
  60. while(true) {}
  61. }, 500);
  62. setTimeout(() => {
  63. window.close();
  64. }, 1000);
  65. });
  66. }
  67. }
  68.  
  69. setTimeout(() => {
  70. injectBlockImage();
  71. crashAndClose();
  72. }, 3000);
  73. })();

QingJ © 2025

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