Scratch Upgrade

Upgrade Scratch and Turbowarp to the next level.

目前为 2022-09-07 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name Scratch Upgrade
  3. // @namespace -
  4. // @version 1
  5. // @description Upgrade Scratch and Turbowarp to the next level.
  6. // @author Plantt
  7. // @match https://scratch.mit.edu
  8. // @match https://scratch.mit.edu/*
  9. // @match https://turbowarp.org/*
  10. // @icon https://scratch.mit.edu/favicon.ico
  11. // @grant none
  12. // @license MIT
  13. // ==/UserScript==
  14.  
  15. var ccInterval;
  16. window.onload = function(event) {
  17. setTimeout(function(){
  18. if (document.URL.substring(0, "https://scratch.mit.edu/projects/".length) == "https://scratch.mit.edu/projects/"
  19. || document.URL.substring(0, "https://turbowarp.org/".length) == "https://turbowarp.org/") {
  20. setInterval(function() {if (document.getElementById("hcBtn") == null) {
  21. var hcBtn = document.createElement("button");
  22. hcBtn.innerText = "Hide Cursor";
  23. hcBtn.id = "hcBtn";
  24. hcBtn.style.height = "20px";
  25. hcBtn.onclick = function() {hideCursor()};
  26. document.querySelector(".controls_controls-container_2xinB").appendChild(hcBtn);
  27. var randomVal = document.createElement("input");
  28. randomVal.type = "number";
  29. randomVal.value = -1;
  30. randomVal.step = "any";
  31. randomVal.id = "rndVal";
  32. randomVal.size = 3;
  33. randomVal.style.marginLeft = "10px";
  34. randomVal.style.height = "20px";
  35. var randomFunc = Math.random;
  36. randomVal.onchange = e => {
  37. if (e.target.value == "-1") {
  38. Math.random = randomFunc;
  39. }
  40. else {
  41. eval("Math.random = () => " + e.target.value);
  42. }
  43. }
  44. document.querySelector(".controls_controls-container_2xinB").appendChild(randomVal);
  45. var sinCosSwap = document.createElement("button");
  46. sinCosSwap.innerText = "Swap sin() and cos()";
  47. sinCosSwap.id = "sin-cos-swap";
  48. sinCosSwap.style.marginLeft = "10px";
  49. sinCosSwap.style.height = "20px";
  50. sinCosSwap.onclick = e => {
  51. var tmp = Math.sin;
  52. Math.sin = Math.cos;
  53. Math.cos = tmp;
  54. }
  55. document.querySelector(".controls_controls-container_2xinB").appendChild(sinCosSwap);
  56. }}, 42);
  57. }
  58. if (document.URL == location.origin + "/") {
  59. for (var i = 0; i < document.querySelectorAll("div.box-header").length; i++) {
  60. makeCollapsible(document.querySelectorAll("div.box-header")[i]);
  61. }
  62. }
  63. if (document.URL.substring(0, (location.origin + "/search").length) == location.origin + "/search"
  64. || document.URL.substring(0, (location.origin + "/explore").length) == location.origin + "/explore") {
  65. var btn = document.createElement("button");
  66. btn.innerText = "Get a random project";
  67. btn.onclick = goToRandomProject;
  68. document.querySelector("div.sort-controls").appendChild(btn);
  69. }
  70. if (document.URL == "https://scratch.mit.edu/messages/") {
  71. var delBtn = document.createElement("button");
  72. delBtn.innerText = "Delete all studio messages";
  73. delBtn.style = `
  74. transition: border .5s ease;
  75. margin-bottom: .75rem;
  76. border: 1px solid rgba(0, 0, 0, 0.1);
  77. border-radius: 5px;
  78. background-color: #fefefe;
  79. padding-right: 4rem;
  80. padding-left: 1rem;
  81. width: 100%;
  82. height: 3rem;
  83. color: #575e75;
  84. font-size: .875rem;
  85. -webkit-appearance: none;
  86. -moz-appearance: none;
  87. appearance: none;
  88. `;
  89. delBtn.onclick = function() {
  90. var a = document.querySelectorAll("li.mod-studio-activity");
  91. for (var i = 0; i < a.length; i++) a[i].remove();
  92. }
  93. document.querySelector("div.mod-messages-title").appendChild(delBtn);
  94. }
  95. }, 1000);
  96. }
  97. function hideCursor() {
  98. clearInterval(ccInterval);
  99. ccInterval = setInterval(function() {
  100. document.querySelector("div.stage_stage_1fD7k.box_box_2jjDp div canvas").style.cursor = "none";
  101. }, 42);
  102. document.getElementById("hcBtn").innerText = "Show cursor";
  103. document.getElementById("hcBtn").onclick = function(){showCursor();};
  104. }
  105. function showCursor() {
  106. clearInterval(ccInterval);
  107. ccInterval = setInterval(function() {
  108. document.querySelector("div.stage_stage_1fD7k.box_box_2jjDp div canvas").style.cursor = null;
  109. }, 42);
  110. document.getElementById("hcBtn").innerText = "Hide cursor";
  111. document.getElementById("hcBtn").onclick = function(){hideCursor();};
  112. }
  113. function makeCollapsible(header) {
  114. var btn = document.createElement("button");
  115. btn.style.marginLeft = "20px";
  116. expand();
  117. header.appendChild(btn);
  118. function collapse() {
  119. header.parentElement.querySelector("div.box-content").style.display = "none";
  120. header.parentElement.style.height = "36px";
  121. btn.innerText = "Expand";
  122. btn.onclick = expand;
  123. }
  124. function expand() {
  125. header.parentElement.querySelector("div.box-content").style.display = "block";
  126. header.parentElement.style.height = "";
  127. btn.innerText = "Collapse";
  128. btn.onclick = collapse;
  129. }
  130. }
  131. function goToRandomProject() {
  132. document.querySelectorAll("div.thumbnail-title")[Math.floor(Math.random() * document.querySelectorAll("div.thumbnail-title").length)].querySelector("a").click();
  133. }