Skip to content

Local Overrides Sample: Hide some Main Menu items from non‐admin users

bp2008 edited this page Feb 12, 2024 · 3 revisions

This script is a starting point for hiding specific main menu items from non-admin users. To edit the list of main menu items that are hidden, load this script, then inspect the source of the main menu while it is open to learn which CSS class names are used. Then modify the call to myCss at the bottom of the script to make it hide the menu items you want.

To learn more about ui3-local-overrides.js, see: Local Overrides Scripts and Styles

ui3-local-overrides.js

(function ()
{
    // Hide some main menu items for non-admins

    var myCss = InjectStyleBlock("");

    // We've just injected an empty `<style type="text/css"></style>` element into the DOM.
    // `myCss` is a function you can call and pass in a string of CSS markup to assign to the style element.

    // First, make sure each menu item has a predictable unique CSS class
    BI_CustomEvent.AddListener("DropdownBoxes_Initializing", function (dropdownBoxes)
    {
        dropdownBoxes.listDefs["mainMenu"].items.forEach(function (item)
        {
            if (!item.cssClass)
                item.cssClass = "";
            item.cssClass += " main_menu_" + item.cmd;
        });
    });

    // Upon receiving session status ("Login Success" event), assign the desired CSS.
    BI_CustomEvent.AddListener("Login Success", function (response)
    {
        if (response.data.admin)
            myCss(""); // Don't hide any buttons
        else
        {
            // Hide the listed buttons (including the playback settings button)
            myCss(".main_menu_streaming_profiles, .main_menu_user_list, .main_menu_device_list { display: none !important; }");
        }
    });
})();
Clone this wiki locally