Greasy Fork

Greasy Fork is available in English.

Turbowarp for Scratch

Converts the project page & editor to Turbowarp versions.

当前为 2023-06-27 提交的版本,查看 最新版本

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Greasemonkey 油猴子Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Violentmonkey 暴力猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴Userscripts ,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展,例如 Tampermonkey 篡改猴,才能安装此脚本。

您需要先安装一款用户脚本管理器扩展后才能安装此脚本。

(我已经安装了用户脚本管理器,让我安装!)

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展,比如 Stylus,才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

您需要先安装一款用户样式管理器扩展后才能安装此样式。

(我已经安装了用户样式管理器,让我安装!)

// ==UserScript==
// @name         Turbowarp for Scratch
// @namespace    http://tampermonkey.net/
// @version      1.1
// @description  Converts the project page & editor to Turbowarp versions.
// @author       You
// @match        https://scratch.mit.edu/projects/*
// @match        https://turbowarp.org/*
// @icon         https://turbowarp.org/images/192.png
// @license      MIT
// @grant        none
// ==/UserScript==

if (document.location.href.includes('turbowarp') && document.referrer == 'https://scratch.mit.edu/') {
    console.log('Came from Turbowarp for Scratch');
} else {
setInterval(function() {
  if (document.location.href == 'https://scratch.mit.edu/projects/editor/') {
      window.onbeforeunload = null;
      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) {
        url = url.replace(/\/+$/, '');

        var segments = url.split('/');
        var projectId = segments[segments.length - 2];

        return projectId;
      }

      var projectId = extractProjectId(document.location.href);
        const state = { page_id: 1, user_id: 5 };
        const url = document.location.href.replace(/(https:\/\/scratch\.mit\.edu\/projects\/\d+\/).*/, "$1");
        history.pushState(state, "", url);
        window.onbeforeunload = null;
        document.location.href = `https://turbowarp.org/${projectId}/editor`;
    }
  }
}, 100);

const observer = new MutationObserver((mutationsList) => {
  for (const mutation of mutationsList) {
    if (mutation.type === 'childList' && mutation.addedNodes.length > 0) {
      const targetElement = document.querySelector("#view > div > div.inner > div:nth-child(2) > div.guiPlayer");

      if (targetElement) {
        function extractProjectId(url) {
          url = url.replace(/\/+$/, '');
          var segments = url.split('/');
          var projectId = segments[segments.length - 1];

          return projectId;
        }

        var projectId = extractProjectId(document.location.href);

        document.querySelector("#view > div > div.inner > div:nth-child(2) > div.guiPlayer").innerHTML = `<iframe src="https://turbowarp.org/${projectId}/embed?addons=pause&settings-button" width="490" height="414" allowtransparency="true" frameborder="0" scrolling="no" allowfullscreen></iframe>`

        observer.disconnect();
      }
    }
  }
});

observer.observe(document.body, { childList: true, subtree: true });
}