diff --git a/public/scripts/power-user.js b/public/scripts/power-user.js index b95973ee50..29174b559b 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; + }); +});