Skip to content

Commit

Permalink
add short button vibration feature
Browse files Browse the repository at this point in the history
  • Loading branch information
6a67 committed Dec 23, 2024
1 parent dbaab5d commit dd06dd0
Showing 1 changed file with 23 additions and 1 deletion.
24 changes: 23 additions & 1 deletion script.user.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// ==UserScript==
// @name JPDB Userscript (6a67)
// @namespace http://tampermonkey.net/
// @version 0.1.180
// @version 0.1.181
// @description Script for JPDB that adds some styling and functionality
// @match *://jpdb.io/*
// @grant GM_addStyle
Expand Down Expand Up @@ -269,6 +269,11 @@
});

settings.showAdvancedSettings = new UserSetting('showAdvancedSettings', false, 'Show advanced settings');
settings.advancedShortButtonVibration = new UserSetting('advancedShortButtonVibration', false, 'Short button vibration', {
longDescription:
'Vibrate the device for a short duration when a positive button is pressed. Only works if button styling is enabled.',
dependency: settings.showAdvancedSettings
});
settings.advancedStaticAnswerButtonsOnSmallScreens = new UserSetting(
'advancedStaticAnswerButtonsOnSmallScreens',
false,
Expand Down Expand Up @@ -1653,6 +1658,18 @@
}
}

function vibrateDeviceButton(button) {
if (!navigator.vibrate) {
return;
}

if (button.classList.contains('v1')) {
return;
}

navigator.vibrate([15]);
}

async function playEffect(button) {
if (button.classList.contains('v1')) {
return;
Expand Down Expand Up @@ -1756,6 +1773,11 @@
if (USER_SETTINGS.enableButtonSound()) {
await playButtonSound(button);
}

if (USER_SETTINGS.advancedShortButtonVibration()) {
vibrateDeviceButton(button);
}

const form = button.closest('form');
if (form) {
form.submit();
Expand Down

0 comments on commit dd06dd0

Please sign in to comment.