-
Notifications
You must be signed in to change notification settings - Fork 0
/
editor.html
185 lines (173 loc) · 13.8 KB
/
editor.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
<!doctype html><html><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width,initial-scale=1"><meta name="google" value="notranslate"><meta name="description" content="TurboWarp is a Scratch mod with a compiler to run projects faster, dark mode for your eyes, a bunch of addons to improve the editor, and more."/><title>TurboWarp - Run Scratch projects faster</title><link rel="apple-touch-icon" href="images/apple-touch-icon.png"><link rel="manifest" href="manifest.webmanifest"><style>#splash {
position: absolute; width: 100%; height: 100%; top: 0; left: 0;
display: flex; align-items: center; justify-content: center;
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif; color: #1fd700;
}
.tw-loaded #splash, #splash-content { display: none; }
#splash[splash-theme="dark"] { background-color: #000367; color: #fff; }
#splash-spinner:after {
content: " "; display: block; width: 64px; height: 64px;
border-radius: 50%; border: 6px solid; border-color: currentColor transparent currentColor transparent;
animation: splash-spinner 1.2s linear infinite;
}
@keyframes splash-spinner {
0% { transform: rotate(0deg); }
100% { transform: rotate(360deg); }
}</style><link rel="dns-prefetch" href="https://trampoline.turbowarp.org/"><link rel="dns-prefetch" href="https://projects.scratch.mit.edu/"><link rel="dns-prefetch" href="https://assets.scratch.mit.edu/"></head><body><div id="splash" aria-hidden="true"><noscript><h1>Enable JavaScript</h1></noscript><div id="splash-content"><div id="splash-spinner"></div></div></div><script>(function() {
document.querySelector('#splash-content').style.display = 'block';
try {var localTheme = localStorage.getItem('tw:theme');} catch (e) {}
if (localTheme ? localTheme === 'dark' : window.matchMedia('(prefers-color-scheme: dark)').matches) document.querySelector('#splash').setAttribute('splash-theme', 'dark');
})();</script><div id="app"></div><script src="js/vendors~addon-settings~credits~editor~embed~fullscreen~player.87367b5121c5a3b0a0f1.js"></script><script src="js/vendors~editor~embed~fullscreen~player.14c5972d6c5fac48fdbb.js"></script><script src="js/addon-settings~addons~editor~fullscreen~player.2cc7ea78b69a28d3d20f.js"></script><script src="js/editor~embed~fullscreen~player.06c3a0916aa7d4d2f248.js"></script><script src="js/editor.302f4f250387bf5eb759.js"></script><script>// ==UserScript==
// @name Plugin loader UI
// @namespace https://lstv.ml/
// @version 0.4
// @description Adds an UI option to quickly load plugins. Supports packager too.
// @author LSTV
// @match https://turbowarp.org/editor*
// @match *://packager.turbowarp.org/*
// @icon https://www.google.com/s2/favicons?domain=turbowarp.org
// @grant none
// @license MIT
// @downloadURL none
// ==/UserScript==
/* Preets;
Setup your presets here.
When there is [R] at the begining, the "url" parametter is gonna be treated like url, if there is not, it's gonna be treated like pure code.*/
const presets=[
{"name":"UtilsV2","url":"[R]https://raw.githubusercontent.com/lukas-studio-tv/TurboWarpPluginUI/main/data/plugins/UtilsV2-12.js","color":"lime"},
{"name":"GameJoltAPI [Beta]","url":"[R]https://raw.githubusercontent.com/lukas-studio-tv/TurboWarpPluginUI/main/data/plugins/GameJoltAPI-11.js","color":"#2f7f6f"},
{"name":"Scratch Noise","url":"[R]https://raw.githubusercontent.com/David-Orangemoon/Modified-Extension-Loader-Turbowarp/main/custom%20extensions/Noise.js","color":"purple"},
{"name":"Audio Manager","url":"[R]https://raw.githubusercontent.com/lukas-studio-tv/TurboWarpPluginUI/main/data/plugins/AudioStream-12.js","color":"#21c7ff"},
{"name":"Audio Manager Legacy","url":"[R]https://raw.githubusercontent.com/lukas-studio-tv/another-lstv-proxy/main/docs/ws-clone/ml/cdn/dock-snapshot-12422/uploaded-raw-content/ekCNWxYHTAAudioManager.js","color":"#21c7ff"},
{"name":"Gamepad","url":"[R]https://romadillo.github.io/Useful-Scratch-Extensions/Gamepad.js","color":"#e4b100"},
{"name":"Cookies","url":"[R]https://raw.githubusercontent.com/David-Orangemoon/Modified-Extension-Loader-Turbowarp/main/custom%20extensions/Cookie.js","color":"#755848"},
{"name":"Xtra Math","url":"[R]https://raw.githubusercontent.com/David-Orangemoon/Modified-Extension-Loader-Turbowarp/main/custom%20extensions/Extramath.js","color":"#5cb712"},
{"name":"CloudLink","url":"[R]https://mikedev101.github.io/cloudlink/S4-0-nosuite.js","color":"lime"},
{"name":"Pen+","url":"[R]https://raw.githubusercontent.com/David-Orangemoon/Modified-Extension-Loader-Turbowarp/main/custom%20extensions/CustomRenderPipeline.js","color":"#0e9a6b"},
{"name":"DBU+","url":"[R]https://raw.githubusercontent.com/David-Orangemoon/Modified-Extension-Loader-Turbowarp/main/custom%20extensions/UpgradedDangerousBusUseful.js","color":"#eb5e34"},
{"name":"Speech 2 Text","url":"[R]https://raw.githubusercontent.com/David-Orangemoon/Modified-Extension-Loader-Turbowarp/main/custom%20extensions/Speech2Text.js","color":"#9addc9"}
];
var isPackager=location.host.includes("packager");
/*
You can also load plugins from the console instead of using an UI (For example if you need to load a plugin from url) like this:
window.loadPlugin("[R]https://example.com")
The [R] indicates url. If you don't include it, it will get loaded as the code.
*/
/*code*/
window.cPluginURL="";
window.plRefreshPluginPresets = function() {
var container;
//if(isPackager){
// container = document.querySelector(".pk_preset_c");
// container.innerHTML = "";
// for (let i=0;i<presets.length;i++) {
// var icon="plus-square";
// if(twp_ta.value.includes(presets[i].url.substring(3,presets[i].url.length))){icon="trash-fill"}
// container.innerHTML = container.innerHTML + `<div class="pl_preset" onclick='addTWPPlugin("`+presets[i].url+`",this)'></span><i class="bi bi-`+icon+`" style="color:`+presets[i].color+`;margin-right:7px;"></i>`+presets[i].name + `</div>`;
// }
//}//else{
container = document.querySelector(".pl_preset_c");
container.innerHTML = "";
for (let i = 0;i< presets.length;i++) {
container.innerHTML = container.innerHTML + `<div class="pl_preset" onclick='loadPlugin("` + presets[i].url + "?update=" + Math.floor(Math.random() * 1001) + `")'><span class="plcspan" style="background:` + presets[i].color + `;"> ` + presets[i].name + `</div>`;
}
//}
}
const RequestNetwork={sendRequest:function(a,b){RequestNetwork.sucess=!0,fetch(a).then(a=>a.text()).then(a=>{RequestNetwork.onRequestResponseRecived(a,b)}).catch(a=>{RequestNetwork.sucess=!1,RequestNetwork.onError(a,b)})},onRequestResponseRecived:function(a,b){console.log(b+", "+a)},onError:function(a,b){console.error("Fetch error, tag:"+b+", error: "+a)},sucess:!1};
if(!isPackager){
var plbtn = document.createElement('div'),
elm = document.createElement('div');
plbtn.className = "menu-bar_menu-bar-item_oLDa- menu-bar_hoverable_c6WFB";
plbtn.innerHTML = '<div><span>Plugins</span></div>';
window.loadPlugin = function(pl) {
if (pl.substring(0, 10).includes("[R]")) {
window.cPluginURL=pl.substring(3, pl.length);
RequestNetwork.sendRequest(pl.substring(3, pl.length), 'load');
} else {
try {
eval(pl);
document.querySelector(".plmenu").style.display = "none";
document.querySelector(".plinput").value = "";
document.querySelector(".pltextarea").value = "";
alert("Plugin loaded. You should now see it in your blocks pallete");
} catch (e) {
alert("Error loading plugin:\n" + e)
}
}
}
setTimeout(function() {
var canvas = document.getElementById("app")
canvas = canvas.children[0]
canvas = canvas.children[0]
canvas = canvas.children[0]
canvas = canvas.children[1]
canvas = canvas.children[0]
canvas = canvas.children[0].appendChild(plbtn);
//document.querySelector("#app > div > div > div > div.gui_menu-bar-position_3U1T0.menu-bar_menu-bar_JcuHF.box_box_2jjDp > div.menu-bar_main-menu_3wjWH > div.menu-bar_file-group_1_CHX").appendChild(plbtn);
plbtn.addEventListener('click', function(e) {
document.querySelector(".plmenu").style.display = "block";
document.querySelector(".plinput").value = "";
document.querySelector(".pltextarea").value = "";
window.plRefreshPluginPresets();
})
elm.className = "plmenu";
elm.innerHTML = `
<h1 class="pltitle">Load a custom plugin</h1>
<div class="plmenuix"><br>
<h3>Option 1: Select one of your presets to load:</h3><div class="pl_preset_c"></div><br><br>
<h3>Option 2: Paste the extension code here:</h3><br><textarea class='pltextarea'></textarea><br><button onclick='window.loadPlugin(document.querySelector(".pltextarea").value)' class='plbutton' style="width:92%;">Load</button><br><br>
<h3>Option 3: Or load from an URL</h3><br><br><input type='text' class='plinput' placeholder='Enter an plugin URL'><button onclick='window.loadPlugin("[R]"+document.querySelector(".plinput").value)' class='plbutton'>Load</button><br><br><button onclick='document.querySelector(".plmenu").style.display="none";' class='plbutton' style="color:black;background:white;">Cancel</button></div></div>`;
document.body.append(elm);
elm = document.createElement('style');
elm.innerHTML = `/* Style */
.pltitle{background:#2d2d2d;position:absolute;top:0px;left:0px;right:0px;height:40px;}
.plmenu{display:none;text-align:center;position:fixed;z-index:99;top:90px;right:380px;left:380px;border-radius:5px;border:5px solid rgba(93, 93, 93,.6);padding:0px;padding-top:40px;min-width:450px;user-select:none;}
.plmenuix{padding:15px;background:#111111;}
.plbutton{background:#fd4c4c;border-radius:5px;padding:10px;border:none;}
.pltextarea{resize:none;height:2px;width:90%;}
.plinput,.pltextarea{color:white;border:1px solid #2d2d2d;border-radius:5px;outline:none;background:#1e1e1e;padding:9px;}
`;
document.body.append(elm);
}, 800);
}else{
setTimeout(function(){
var plcat=`<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/[email protected]/font/bootstrap-icons.css"><div class="card svelte-1qy2cex" style="border-top: 6px solid #F00"><div><h2>Plugins [BETA]</h2><i>Added by the plugin loader UI</i><br>You can add more presets in the script's preset configuration.<br>With this addon you can simply add or remove plugins!<br>+ It (should) save your plugins for this project - even after refresh and with offline access.<br><br><div class="pk_preset_c"><i>Your presets should be displayed here.</i></div></div></div>`;
//window.plAppendToPackager=function(){
// if(document.querySelectorAll(".card")[4]==null){setTimeout(function(){plAppendToPackager()},250)}else{document.querySelectorAll(".card")[4].outerHTML+=plcat;window.twp_ta=document.querySelectorAll("textarea")[2]; if(!twp_ta.value.includes("/* The plugin UI")){twp_ta.value+="/* The plugin UI will add plugins here! Feel free to add your own code, but make sure you do not interrupt the comment blocks indicating plugin start and plugin end.*/\n\n\n"};window.plRefreshPluginPresets();}
//}
document.querySelector("button").addEventListener("click",plAppendToPackager)},100);
window.addTWPPlugin=function(url,src){
window.cPluginSRC=src.querySelector("i");
if(twp_ta.value.includes(url.substring(3,url.length))){
removeTWPPlugin(url.substring(3,url.length));
}else{
window.cPluginURL=url.substring(3,url.length);
RequestNetwork.sendRequest(url.substring(3,url.length)+"?update="+Math.floor(Math.random()*1001),'loadtwp');}
}
window.removeTWPPlugin=function(url){
var safeUrl=url.replaceAll("/","\\\/").replaceAll(".","\\\.").replaceAll(":","\\\:");
var rgx=new RegExp('\\/\\*\\!\\[loader\]\\[start\\:'+safeUrl+'\\]\\!\\*\\/(.*?)\\/\\*\\!\\[loader\]\\[end\\:'+safeUrl+'\\]\\!\\*\\/', 'is');
document.querySelectorAll("textarea")[2].value=document.querySelectorAll("textarea")[2].value.replace(rgx,"");
cPluginSRC.classList.add("bi-plus-square");
cPluginSRC.classList.remove("bi-trash-fill");
}
}
var globalStyles=`<style>.pl_preset{background:#333333;color:white;padding:0px;border-radius:0px;display:inline-block;cursor:pointer;margin-bottom:0.1%;margin-right:40%;margin-left:40%}.plcspan{border-radius:0px;padding:0px;width:25px;height:25px;}</style>`;
setTimeout(function(){document.body.insertAdjacentHTML("afterend",globalStyles);},2000);
RequestNetwork.onError=function(error, tag) {
alert("Failed to load plugin from an url. \nPlease make sure that:\n- You are connected to the internet\n- Plugin is loaded over HTTPS\n- That the url has Access-Control-Allow-Origin set to '*'\n\n(Look to the console for details)");
}
RequestNetwork.onRequestResponseRecived=function(response, tag) {
if(RequestNetwork.sucess){
console.log('Trying to load plugin');
if(tag=="load"){
window.loadPlugin(response);
}else if(tag=="loadtwp"){
var plug="/*![loader][start:"+cPluginURL+"]!*/"+response+"/*![loader][end:"+cPluginURL+"]!*/";
twp_ta.value+=plug;
var evt=new Event('input');twp_ta.dispatchEvent(evt);/*Simulates manual input to force saving the plugin into cache for the current project*/
cPluginSRC.classList.remove("bi-plus-square");
cPluginSRC.classList.add("bi-trash-fill");
}
}
}</script></body></html>