Skip to content

Commit

Permalink
Create Vibrations.js
Browse files Browse the repository at this point in the history
  • Loading branch information
BlueDome77 authored Jul 23, 2023
1 parent 1455ba8 commit 9c8ef6f
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions Extensions/Vibrations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,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);

0 comments on commit 9c8ef6f

Please sign in to comment.