Skip to content

Commit c1b75b5

Browse files
committed
Add addon tw-disable-vibration
Closes #1120 Closes #877 We can add options for either later, if someone asks
1 parent ddd23a3 commit c1b75b5

File tree

7 files changed

+57
-1
lines changed

7 files changed

+57
-1
lines changed

src/addons/addons.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const addons = [
7878
'tw-straighten-comments',
7979
'tw-remove-backpack',
8080
'tw-remove-feedback',
81+
'tw-disable-vibration',
8182
'tw-disable-cloud-variables',
8283
'tw-disable-compiler',
8384
'editor-stepping'
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/* generated by pull.js */
2+
const manifest = {
3+
"noTranslations": true,
4+
"name": "Disable vibrations",
5+
"description": "Prevents the vibration and gamepad extensions from causing vibrations.",
6+
"userscripts": [
7+
{
8+
"url": "userscript.js"
9+
}
10+
],
11+
"tags": [
12+
"danger"
13+
],
14+
"enabledByDefault": false
15+
};
16+
export default manifest;
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
/* generated by pull.js */
2+
import _js from "./userscript.js";
3+
export const resources = {
4+
"userscript.js": _js,
5+
};
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
export default async function ({ addon }) {
2+
if (navigator.vibrate) {
3+
const originalVibrate = navigator.vibrate;
4+
navigator.vibrate = function (...args) {
5+
if (addon.self.disabled) {
6+
return originalVibrate.call(this, ...args);
7+
}
8+
return false;
9+
};
10+
}
11+
12+
if (typeof GamepadHapticActuator === 'function' && typeof GamepadHapticActuator.prototype.pulse === 'function') {
13+
const originalPulse = GamepadHapticActuator.prototype.pulse;
14+
GamepadHapticActuator.prototype.pulse = function (...args) {
15+
if (addon.self.disabled) {
16+
return originalPulse.call(this, ...args);
17+
}
18+
return Promise.resolve(false);
19+
};
20+
}
21+
22+
if (typeof GamepadHapticActuator === 'function' && typeof GamepadHapticActuator.prototype.playEffect === 'function') {
23+
const originalPlayEffect = GamepadHapticActuator.prototype.playEffect;
24+
GamepadHapticActuator.prototype.playEffect = function (...args) {
25+
if (addon.self.disabled) {
26+
return originalPlayEffect.call(this, ...args);
27+
}
28+
return Promise.resolve('preempted');
29+
};
30+
}
31+
}

src/addons/generated/addon-entries.js

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/addons/generated/addon-manifests.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,7 @@ import _hide_stage from "../addons/hide-stage/_manifest_entry.js";
7676
import _tw_straighten_comments from "../addons/tw-straighten-comments/_manifest_entry.js";
7777
import _tw_remove_backpack from "../addons/tw-remove-backpack/_manifest_entry.js";
7878
import _tw_remove_feedback from "../addons/tw-remove-feedback/_manifest_entry.js";
79+
import _tw_disable_vibration from "../addons/tw-disable-vibration/_manifest_entry.js";
7980
import _tw_disable_cloud_variables from "../addons/tw-disable-cloud-variables/_manifest_entry.js";
8081
import _tw_disable_compiler from "../addons/tw-disable-compiler/_manifest_entry.js";
8182
import _editor_stepping from "../addons/editor-stepping/_manifest_entry.js";
@@ -157,6 +158,7 @@ export default {
157158
"tw-straighten-comments": _tw_straighten_comments,
158159
"tw-remove-backpack": _tw_remove_backpack,
159160
"tw-remove-feedback": _tw_remove_feedback,
161+
"tw-disable-vibration": _tw_disable_vibration,
160162
"tw-disable-cloud-variables": _tw_disable_cloud_variables,
161163
"tw-disable-compiler": _tw_disable_compiler,
162164
"editor-stepping": _editor_stepping,
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
{"commit":"f41d6de"}
1+
{"commit":"965a016"}

0 commit comments

Comments
 (0)