Skip to content

Local Overrides Sample: Hide some UI Settings from non‐admin users

bp2008 edited this page Feb 12, 2024 · 1 revision

This script is a starting point for hiding specific UI Settings from non-admin users. To use this script most easily, use UI3's Create Script: "ui3-local-overrides.js" Download button at the bottom of UI Settings while logged in as an admin. This downloads a ui3-local-overrides.js file containing OverrideDefaultSetting method calls for each of your current settings. You can copy the lines you want into the overrideSettings method below and change the 3rd argument value to the a variable as demonstrated below for the ui3_preferred_ui_scale setting.

NOTE: UI3-268 or later fixes some bugs in the handling of the IncludeInOptionsWindow argument which are helpful for this script to function properly.

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

ui3-local-overrides.js

(function ()
{
    function overrideSettings(a)
    {
        // 3rd argument is "IncludeInOptionsWindow".  Should be true to allow this setting to be shown in the options window.
        OverrideDefaultSetting("ui3_preferred_ui_scale", "Auto", a, false, 1);
    }

    // Override settings now before UI loading processes the default settings array
    overrideSettings(true);

    // Then override again each time UI3 receives session status, because the admin flag may change.
    BI_CustomEvent.AddListener("Login Success", function (response)
    {
        overrideSettings(!!response.data.admin);
    });
})();
Clone this wiki locally