Squabbles.io Normalize Buttons

Normalizes "circular" buttons into actual circles.

14.06.2023 itibariyledir. En son verisyonu görün.

// ==UserScript==
// @name         Squabbles.io Normalize Buttons
// @namespace    https://github.com/waaamb/userscripts
// @version      0.1.1
// @description  Normalizes "circular" buttons into actual circles.
// @author       Waaamb
// @match        *://*.squabbles.io/*
// @icon         https://www.google.com/s2/favicons?sz=64&domain=squabbles.io
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    /* Settings */
    /* These are settings variables to enable features.
    /* Keep in mind they'll be erased if the script is updated.              */

    const enableNormalizeButtons = true;
    const navbarButtonsSize = '2.5em';

    /* Currently the navbar buttons are all slightly different shapes
    /* and sizes. This function normalizes them all into circles.
    /*
    /* If buttons are added in other locations this function will have
    /* to be refactored.                                                     */

    function normalizeButtons () {
        // Select the "circular" navbar buttons.
        const navbarButtonsSelector = '.navbar .container > div:last-of-type .rounded-circle';

        // Watch the DOM for new buttons...
        const navbarButtonsObserver = new MutationObserver(function () {
            let navbarButtons = document.querySelectorAll(navbarButtonsSelector);

            // ...and modify their style to be round and centered
            for (let button of navbarButtons) {
                button.style.display = 'flex';
                button.style.width = navbarButtonsSize;
                button.style.height = navbarButtonsSize;
                button.style.padding = '0';
                let buttonIcon = button.querySelector('i');
                if (buttonIcon) { buttonIcon.style.margin = 'auto'; }
            }
        });

        const target = document.querySelector('body');
        const config = { subtree: true, childList: true };
        navbarButtonsObserver.observe(target, config);
    }

    enableNormalizeButtons ? normalizeButtons() : false;
})();