diff --git a/webapp/templates/twitch-moderation.html b/webapp/templates/twitch-moderation.html index 956245c..fb487fb 100644 --- a/webapp/templates/twitch-moderation.html +++ b/webapp/templates/twitch-moderation.html @@ -889,6 +889,28 @@ document.addEventListener('keydown', function(e) { var shoutboxKnownIds = new Set(); var shoutboxLastTimestamp = ''; var shoutboxAutoScroll = true; +var shoutboxTabVisible = true; +var shoutboxAudioCtx = null; + +document.addEventListener('visibilitychange', function() { + shoutboxTabVisible = !document.hidden; +}); + +function shoutboxBeep() { + try { + if (!shoutboxAudioCtx) shoutboxAudioCtx = new (window.AudioContext || window.webkitAudioContext)(); + var osc = shoutboxAudioCtx.createOscillator(); + var gain = shoutboxAudioCtx.createGain(); + osc.connect(gain); + gain.connect(shoutboxAudioCtx.destination); + osc.frequency.value = 660; + osc.type = 'sine'; + gain.gain.setValueAtTime(0.15, shoutboxAudioCtx.currentTime); + gain.gain.exponentialRampToValueAtTime(0.001, shoutboxAudioCtx.currentTime + 0.3); + osc.start(shoutboxAudioCtx.currentTime); + osc.stop(shoutboxAudioCtx.currentTime + 0.3); + } catch(e) {} +} var SHOUTBOX_COLORS = [ '#6366f1', '#8b5cf6', '#ec4899', '#14b8a6', '#f59e0b', @@ -946,6 +968,8 @@ function addShoutboxItem(item) { display.appendChild(line); + if (!shoutboxTabVisible) shoutboxBeep(); + while (display.children.length > 200) display.removeChild(display.firstChild); if (shoutboxAutoScroll) display.scrollTop = display.scrollHeight; }