Skip to content

Commit

Permalink
New extension: Vibration (#1509)
Browse files Browse the repository at this point in the history
  • Loading branch information
PwLDev authored Jun 9, 2024
1 parent 2b0318f commit af35fb4
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 0 deletions.
61 changes: 61 additions & 0 deletions extensions/PwLDev/vibration.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
// Name: Vibration
// ID: pwldevvibration
// Description: Control the device's vibration. Only works on Android.
// By: PwLDev <https://scratch.mit.edu/users/PwLDev/>
// License: MPL-2.0

(function (Scratch) {
"use strict";

if (!Scratch.extensions.unsandboxed) {
throw new Error("This extension must run unsandboxed in order to work.");
}

class Vibration {
getInfo() {
return {
id: "pwldevvibration",
name: Scratch.translate("Vibration"),
color1: "#45a15c",
color2: "#317041",
color3: "#35523c",
blocks: [
{
blockType: Scratch.BlockType.LABEL,
text: Scratch.translate("Only works on Android."),
},
{
opcode: "start",
blockType: Scratch.BlockType.COMMAND,
text: Scratch.translate("start vibrating for [SECONDS] seconds"),
arguments: {
SECONDS: {
type: Scratch.ArgumentType.NUMBER,
defaultValue: "2",
},
},
},
{
opcode: "stop",
blockType: Scratch.BlockType.COMMAND,
text: Scratch.translate("stop vibrating"),
},
],
};
}

start(args) {
if (navigator.vibrate) {
navigator.vibrate(Scratch.Cast.toNumber(args.SECONDS) * 1000);
}
}

stop() {
if (navigator.vibrate) {
navigator.vibrate(0);
}
}
}

Scratch.extensions.register(new Vibration());
})(Scratch);
1 change: 1 addition & 0 deletions extensions/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"XmerOriginals/closecontrol",
"navigator",
"battery",
"PwLDev/vibration",
"TheShovel/CustomStyles",
"TheShovel/ColorPicker",
"NexusKitten/controlcontrols",
Expand Down
1 change: 1 addition & 0 deletions images/PwLDev/vibration.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit af35fb4

Please sign in to comment.