From 93e1d4b39e85b9dd4ef5ead5c6265552a13dc15c Mon Sep 17 00:00:00 2001 From: Paniphon <128647114+paniphons@users.noreply.github.com> Date: Mon, 10 Apr 2023 10:34:47 +0700 Subject: [PATCH 1/2] Make sound only play if browser is not focused --- public/scripts/power-user.js | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index b95973ee5..29174b559 100644 --- a/public/scripts/power-user.js +++ b/public/scripts/power-user.js @@ -55,8 +55,11 @@ const storage_keys = { sheld_width: "TavernAI_sheld_width" }; +//Updated at the bottom of this script document based on 'focus' and 'blur' events +let browser_has_focus = true; + function playMessageSound() { - if (!power_user.play_message_sound) { + if (!power_user.play_message_sound || browser_has_focus) { return; } @@ -226,4 +229,11 @@ $(document).ready(() => { power_user.play_message_sound = !!$(this).prop('checked'); saveSettingsDebounced(); }); -}); \ No newline at end of file + + $(window).on('focus', function() { + browser_has_focus = true; + }); + $(window).on('blur', function() { + browser_has_focus = false; + }); +}); From d09e81cb944862b8328319e2b0e7a519285ec066 Mon Sep 17 00:00:00 2001 From: SillyLossy Date: Mon, 10 Apr 2023 12:14:16 +0300 Subject: [PATCH 2/2] Update message sound note --- public/notes/message_sound.html | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/public/notes/message_sound.html b/public/notes/message_sound.html index 2bb1a89fc..3386d1d43 100644 --- a/public/notes/message_sound.html +++ b/public/notes/message_sound.html @@ -20,9 +20,9 @@ public/sounds/message.mp3 - - Plays at 80% volume. - +

+ Plays at 80% volume and only if TavernAI window is unfocused. +