forked from BlueDome77/Turbowarp-Extension-List
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Javascript.js
71 lines (64 loc) · 1.72 KB
/
Javascript.js
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
// Original extension by @LilyMakesThings
(function (Scratch) {
'use strict';
const vm = Scratch.vm;
const runtime = vm.runtime;
const isPackaged = runtime.isPackaged;
let allowJSCode = true;
let ineditor = true;
if (!Scratch.extensions.unsandboxed) {
throw new Error('This extension must run unsandboxed');
}
class CustomJS {
getInfo() {
return {
id: 'JavaScript',
name: 'JavaScript',
color1: '#AAAAAA',
blocks: [
{
opcode: 'execute',
func: 'javascript',
blockType: Scratch.BlockType.COMMAND,
text: 'execute [JS]',
arguments: {
JS: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'alert("Hello World!")'
}
}
},
{
opcode: 'evaluateReporter',
func: 'javascript',
blockType: Scratch.BlockType.REPORTER,
text: 'evaluate [JS]',
arguments: {
JS: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Math.random()'
}
}
},
{
opcode: 'evaluateBoolean',
func: 'javascript',
blockType: Scratch.BlockType.BOOLEAN,
text: 'evaluate [JS]',
arguments: {
JS: {
type: Scratch.ArgumentType.STRING,
defaultValue: 'Math.round(Math.random()) === 1'
}
}
},
]
};
}
javascript(args, util) {
const output = eval(args.JS);
return (output) ? output : '';
}
}
Scratch.extensions.register(new CustomJS());
})(Scratch);