-
Notifications
You must be signed in to change notification settings - Fork 3
/
Vibrations.js
40 lines (39 loc) · 1.01 KB
/
Vibrations.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
(function(Scratch) {
"use strict";
class VibrationsExtension {
getInfo() {
return {
id: 'vibrationsextension',
name: 'Vibrations',
color1: '#e0a000',
color2: '#d09000',
color3: '#d09000',
blocks: [
{
opcode: 'isAvail',
text: 'is vibrations available?',
blockType: Scratch.BlockType.BOOLEAN
},
{
opcode: 'vibrate',
text: 'vibrate for [LEN] milliseconds',
blockType: Scratch.BlockType.COMMAND,
arguments: {
LEN: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: 30
}
}
}
]
};
}
isAvail() {
return Scratch.extensions.unsandboxed && typeof navigator.vibrate == "function";
}
vibrate(args) {
if (this.isAvail()) navigator.vibrate(Math.min(args.LEN, 300));
}
}
Scratch.extensions.register(new VibrationsExtension());
})(Scratch);