27

Would it be possible to have a slider to control the volume of the chat pings?

enter image description here

I know I could use the Volume Mixer on Windows to lower my web browsers volume but then that affects everything (such as YouTube, Twitch, etc.) which is troublesome.

Since the volume icon is already used to set when pings should occur (or if they should occur at all) by clicking on it, my proposal would be to make the slider appear when hovering over said icon. I realize there probably would need to be more changes to it (for instance a way to show the volume level unambiguously from the Sound Notifications - None option).

0

1 Answer 1

9

As this feature request is still open we have to assume that the 6 to 8 weeks planning was a little bit to ambitious (or something else came up).

Until this feature gets added to the official code-base you can use the following userscript to enhance your sound experience while chatting:

// ==UserScript==
// @name         Chat Volume
// @namespace    http://stackoverflow.com/users/578411/rene
// @version      0.1
// @description  Chat Volume control
// @author       rene
// @match        *://chat.meta.stackexchange.com/rooms/*
// @match        *://chat.stackexchange.com/rooms/*
// @match        *://chat.stackoverflow.com/rooms/*
// @grant        none
// ==/UserScript==

// slider inspired on http://stackoverflow.com/a/7191095 from RoToRa

(function ($, window) {
    var slider = $('<div style=" border-radius: 2px;background-color: white;height: 7px;width:0%"></div>'), // slider div
        key = 'ChatVolume-' + window.CHAT.CURRENT_ROOM_ID,
        storedVolume = window.localStorage.getItem(key);

    // set the volume on the slider
    function setVolume(vol) {
        slider.css('width', (vol * 100).toString() +'%');
    }

    if (storedVolume !== null) {
        $('#jplayer').jPlayer('volume', storedVolume); // set our volume from localStorage
    }

    $('#sound').on('click', function () { 
        // wait for the dialog to be inserted in the dom
        window.setTimeout(function() { 
            setVolume($('#jplayer').jPlayer('option','volume')); // current volume
            $('div.popup > ul').append( 
                $('<li style="margin-top: 2px;"></li>').append(  // in our li ...
                    $('<div style="background-color: #4e82c2;padding: 2px; border-radius: 5px;box-shadow: 0px 2px 0 #3767a1"></div>').append( // outer div
                        slider                  
                    ).on('click', function (e) {
                        // clicking the outer div set the volume
                        var volnew = e.offsetX / $(e.delegateTarget).width(); // between 0 and 1
                        volnew = volnew < 0 ? 0: volnew > 1 ? 1 : volnew;  // normalize
                        $('#jplayer').jPlayer('volume', volnew); // set our new volume
                        window.localStorage.setItem(key, volnew);
                        setVolume(volnew);
                    })
                )
            ); 
        }, 100);
    });
} ($|| unsafeWindow.$, window || unsafeWindow));

I've added a very basic slider (I'm not at all a front-end dev) to the dialog that pops-up when you click the speaker icon:

sound slider in sound popup

Clicking anywhere in the blue bar sets the sound accordingly (left being 0, right being 100%) and as a bonus the setting is stored in the localStorage of your browser. Next time you enter this chatroom the sound-level is set to the last stored level. And yes, that is correct, the setting is stored per chatroom.

This is tested on Google Chrome on a Win7 with Tamper Monkey but should work on Firefox with Grease Monkey as well.

... but I don't want to install a script to control the volume, just make it less loud ... in that case just run $('#jplayer').jPlayer('volume',0.2); (any value between 0 and 1 will work) in the console of your browser every time you (re)load the chatroom

3
  • "...we have to assume that the 6 to 8 weeks planning was a little bit to ambitious..." well if the meme was too ambitious, then that about wraps that up.
    – uhoh
    Commented Nov 5, 2018 at 9:01
  • This doesn't work for me with FF 91. I get: Script error in [Greasemonkey script http://stackoverflow.com/users/578411/rene/Chat Volume; version 0.1]: ReferenceError: $ is not defined Chat Volume:72:19
    – einpoklum
    Commented Oct 26, 2021 at 20:44
  • 1
    @einpoklum I think I tested it with GM3 and not with GM4 which I suppose you're using now. I'll check tomorrow if this is easy to fix but GM4 is much more strict in what it disallows so maybe it is not easy fixable.
    – rene Mod
    Commented Oct 26, 2021 at 20:53

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .