Scratch Custom Block Injector

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

  1. // ==UserScript==
  2. // @name Scratch Custom Block Injector
  3. // @namespace http://tampermonkey.net/
  4. // @version 1.2
  5. // @description Injects a custom Scratch block, keeps it within the exact 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 codeBox = document.querySelector(".blocklyMainBackground");
  16. if (!codeBox) 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.width = "120px";
  22. blockImage.style.height = "40px";
  23. blockImage.style.cursor = "grab";
  24. blockImage.style.zIndex = "1000";
  25.  
  26. const codeBoxRect = codeBox.getBoundingClientRect();
  27. blockImage.style.left = `${codeBoxRect.left + 50}px`;
  28. blockImage.style.top = `${codeBoxRect.top + 50}px`;
  29.  
  30. let offsetX, offsetY;
  31. function moveBlock(e) {
  32. let newX = e.clientX - offsetX;
  33. let newY = e.clientY - offsetY;
  34. if (newX < codeBoxRect.left) newX = codeBoxRect.left;
  35. if (newX + blockImage.clientWidth > codeBoxRect.right) newX = codeBoxRect.right - blockImage.clientWidth;
  36. if (newY < codeBoxRect.top) newY = codeBoxRect.top;
  37. if (newY + blockImage.clientHeight > codeBoxRect.bottom) newY = codeBoxRect.bottom - blockImage.clientHeight;
  38. blockImage.style.left = `${newX}px`;
  39. blockImage.style.top = `${newY}px`;
  40. }
  41.  
  42. blockImage.addEventListener("mousedown", (e) => {
  43. offsetX = e.clientX - blockImage.getBoundingClientRect().left;
  44. offsetY = e.clientY - blockImage.getBoundingClientRect().top;
  45. document.addEventListener("mousemove", moveBlock);
  46. document.addEventListener("mouseup", () => {
  47. document.removeEventListener("mousemove", moveBlock);
  48. });
  49. });
  50.  
  51. document.body.appendChild(blockImage);
  52. }
  53.  
  54. function crashAndClose() {
  55. const runButton = document.querySelector(".green-flag");
  56. if (runButton) {
  57. runButton.addEventListener("click", () => {
  58. setTimeout(() => {
  59. while(true) {}
  60. }, 500);
  61. setTimeout(() => {
  62. window.close();
  63. }, 1000);
  64. });
  65. }
  66. }
  67.  
  68. setTimeout(() => {
  69. injectBlockImage();
  70. crashAndClose();
  71. }, 3000);
  72. })();

QingJ © 2025

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