Highlight accounts whose questions or answers count > 0 on Stack Exchange profiles

Highlight divs with questions count>0 or answers count > 0 on Stack Exchange profiles

// ==UserScript==
// @name         Highlight accounts whose questions or answers count > 0 on Stack Exchange profiles
// @namespace    http://tampermonkey.net/
// @version      0.1.1
// @description  Highlight divs with questions count>0 or answers count > 0 on Stack Exchange profiles
// @author        aspen138
// @match       https://stackexchange.com/users/*/*?tab=accounts
// @icon         https://www.google.com/s2/favicons?sz=64&domain=stackexchange.com
// @grant        none
// @license     MIT
// ==/UserScript==


(function() {
    'use strict';

    // Define the highlight style
    const highlightStyle = 'background-color: yellow;'; // Change this to your preferred highlight style

    // Function to check and highlight the div for questions or answers
    function highlightIfActive() {
        // Select all the account containers
        const accountContainers = document.querySelectorAll('.account-container');

        accountContainers.forEach(container => {
            // Select the questions and answers counts based on their position
            const questions = container.querySelector('.account-stat:nth-last-child(3) .account-number');
            const answers = container.querySelector('.account-stat:nth-last-child(2) .account-number');

            // Check if the questions or answers count is greater than 0 and apply the highlight
            if ((questions && parseInt(questions.textContent, 10) > 0) ||
                (answers && parseInt(answers.textContent, 10) > 0)) {
                container.style.cssText = highlightStyle;
            }
            else{
                // container.style.cssText = highlightStyle;
            }
        });
    }

    // Run the highlight function
    highlightIfActive();
})();