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

Verze ze dne 07. 05. 2024. Zobrazit nejnovější verzi.

K instalaci tototo skriptu si budete muset nainstalovat rozšíření jako Tampermonkey, Greasemonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Violentmonkey.

K instalaci tohoto skriptu si budete muset nainstalovat rozšíření jako Tampermonkey nebo Userscripts.

You will need to install an extension such as Tampermonkey to install this script.

K instalaci tohoto skriptu si budete muset nainstalovat manažer uživatelských skriptů.

(Už mám manažer uživatelských skriptů, nechte mě ho nainstalovat!)

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install an extension such as Stylus to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

You will need to install a user style manager extension to install this style.

(Už mám manažer uživatelských stylů, nechte mě ho nainstalovat!)

// ==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();
})();