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

اعتبارا من 07-05-2024. شاهد أحدث إصدار.

You will need to install an extension such as Tampermonkey, Greasemonkey or Violentmonkey to install this script.

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

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

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

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

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

(I already have a user script manager, let me install it!)

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.

ستحتاج إلى تثبيت إضافة مثل Stylus لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتتمكن من تثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

ستحتاج إلى تثبيت إضافة لإدارة أنماط المستخدم لتثبيت هذا النمط.

(لدي بالفعل مثبت أنماط للمستخدم، دعني أقم بتثبيته!)

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