// ==UserScript== // @name Turbowarp for Scratch // @namespace http://tampermonkey.net/ // @version 1.0 // @description Converts the project page & editor to Turbowarp versions. // @author ClaytonTDM // @license MIT // @match https://scratch.mit.edu/projects/* // @icon https://turbowarp.org/images/192.png // @grant none // @downloadURL none // ==/UserScript== setInterval(function() { if (document.location.href == 'https://scratch.mit.edu/projects/editor/') { document.location.href = 'https://turbowarp.org/editor'; } else { if (document.location.href.includes('editor') && document.location.href != 'https://scratch.mit.edu/projects/editor/') { function extractProjectId(url) { // Remove trailing slashes if present url = url.replace(/\/+$/, ''); // Split the URL by slashes and get the last segment var segments = url.split('/'); var projectId = segments[segments.length - 2]; return projectId; } // Example usage var projectId = extractProjectId(document.location.href); document.location.href = `https://turbowarp.org/${projectId}/editor`; } } }, 100); // Create a new MutationObserver const observer = new MutationObserver((mutationsList) => { // Check each mutation that occurred for (const mutation of mutationsList) { // Check if the target element was added to the DOM if (mutation.type === 'childList' && mutation.addedNodes.length > 0) { const targetElement = document.querySelector("#view > div > div.inner > div:nth-child(2) > div.guiPlayer"); // Check if the target element is now available in the DOM if (targetElement) { // Call your desired function here function extractProjectId(url) { // Remove trailing slashes if present url = url.replace(/\/+$/, ''); // Split the URL by slashes and get the last segment var segments = url.split('/'); var projectId = segments[segments.length - 1]; return projectId; } // Example usage var projectId = extractProjectId(document.location.href); document.querySelector("#view > div > div.inner > div:nth-child(2) > div.guiPlayer").innerHTML = `` // Disconnect the observer since the target element is found observer.disconnect(); } } } }); // Start observing the document body or any other ancestor element observer.observe(document.body, { childList: true, subtree: true });