-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathjava.js
95 lines (47 loc) · 1.79 KB
/
java.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
// We use class syntax to define our extension object
// This isn't actually necessary, but it tends to look the best
class JavaScriptScratch {
/**
* Scratch will call this method *once* when the extension loads.
* This method's job is to tell Scratch things like the extension's ID, name, and what blocks it supports.
*/
getInfo() {
return {
// `id` is the internal ID of the extension
// It should never change!
// If you choose to make an actual extension, please change this to something else.
// Only the characters a-z and 0-9 can be used. No spaces or special characters.
id: 'jscratch',
// `name` is what the user sees in the toolbox
// It can be changed without breaking projects.
name: 'Javascript',
blocks: [
{
// `opcode` is the internal ID of the block
// It should never change!
// It corresponds to the class method with the same name.
opcode: 'sayfromjavascript',
blockType: Scratch.BlockType.Stack,
text: 'Hello!',
arguments: {
ONE: {
type: Scratch.ArgumentType.STRING,
defaultValue: ''
}
}
]
};
}
/**
* Corresponds to `opcode: 'hello'` above
*/
sayfromjavascript() {
// You can just return a value: any string, boolean, or number will work.
// If you have to perform an asynchronous action like a request, just return a Promise.
// The block will wait until the Promise resolves and return the resolved value.
return alert(args.ONE);
}
}
// Call Scratch.extensions.register to register your extension
// Make sure to register each extension exactly once
Scratch.extensions.register(new JavaScriptScratch());