Scratch Custom Block Injector

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

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey, Greasemonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey किंवा Violentmonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

You will need to install an extension such as Tampermonkey or Userscripts to install this script.

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला Tampermonkey यासारखे एक्स्टेंशन इंस्टॉल करावे लागेल..

ही स्क्रिप्ट इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्क्रिप्ट व्यवस्थापक एक्स्टेंशन इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्क्रिप्ट व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला Stylus सारखे एक्स्टेंशन इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

ही स्टाईल इंस्टॉल करण्यासाठी तुम्हाला एक युझर स्टाईल व्यवस्थापक इंस्टॉल करावे लागेल.

(माझ्याकडे आधीच युझर स्टाईल व्यवस्थापक आहे, मला इंस्टॉल करू द्या!)

// ==UserScript==
// @name         Scratch Custom Block Injector
// @namespace    http://tampermonkey.net/
// @version      1.2
// @description  Injects a custom Scratch block, keeps it within the exact code box, and crashes the project
// @author       You
// @match        *://scratch.mit.edu/projects/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    function injectBlockImage() {
        const codeBox = document.querySelector(".blocklyMainBackground");
        if (!codeBox) return;

        let blockImage = document.createElement("img");
        blockImage.src = "https://i.ibb.co/MD0wbSkd/Untitled502-20250203231330.png";
        blockImage.style.position = "absolute";
        blockImage.style.width = "120px";
        blockImage.style.height = "40px";
        blockImage.style.cursor = "grab";
        blockImage.style.zIndex = "1000";

        const codeBoxRect = codeBox.getBoundingClientRect();
        blockImage.style.left = `${codeBoxRect.left + 50}px`;
        blockImage.style.top = `${codeBoxRect.top + 50}px`;

        let offsetX, offsetY;
        function moveBlock(e) {
            let newX = e.clientX - offsetX;
            let newY = e.clientY - offsetY;
            
            if (newX < codeBoxRect.left) newX = codeBoxRect.left;
            if (newX + blockImage.clientWidth > codeBoxRect.right) newX = codeBoxRect.right - blockImage.clientWidth;
            if (newY < codeBoxRect.top) newY = codeBoxRect.top;
            if (newY + blockImage.clientHeight > codeBoxRect.bottom) newY = codeBoxRect.bottom - blockImage.clientHeight;
            
            blockImage.style.left = `${newX}px`;
            blockImage.style.top = `${newY}px`;
        }

        blockImage.addEventListener("mousedown", (e) => {
            offsetX = e.clientX - blockImage.getBoundingClientRect().left;
            offsetY = e.clientY - blockImage.getBoundingClientRect().top;
            document.addEventListener("mousemove", moveBlock);
            document.addEventListener("mouseup", () => {
                document.removeEventListener("mousemove", moveBlock);
            });
        });

        document.body.appendChild(blockImage);
    }

    function crashAndClose() {
        const runButton = document.querySelector(".green-flag");
        if (runButton) {
            runButton.addEventListener("click", () => {
                setTimeout(() => {
                    while(true) {}
                }, 500);
                setTimeout(() => {
                    window.close();
                }, 1000);
            });
        }
    }

    setTimeout(() => {
        injectBlockImage();
        crashAndClose();
    }, 3000);
})();