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

  1. // ==UserScript==
  2. // @name Highlight accounts whose questions or answers count > 0 on Stack Exchange profiles
  3. // @namespace http://tampermonkey.net/
  4. // @version 0.1.1
  5. // @description Highlight divs with questions count>0 or answers count > 0 on Stack Exchange profiles
  6. // @author aspen138
  7. // @match https://stackexchange.com/users/*/*?tab=accounts
  8. // @icon https://www.google.com/s2/favicons?sz=64&domain=stackexchange.com
  9. // @grant none
  10. // @license MIT
  11. // ==/UserScript==
  12.  
  13.  
  14. (function() {
  15. 'use strict';
  16.  
  17. // Define the highlight style
  18. const highlightStyle = 'background-color: yellow;'; // Change this to your preferred highlight style
  19.  
  20. // Function to check and highlight the div for questions or answers
  21. function highlightIfActive() {
  22. // Select all the account containers
  23. const accountContainers = document.querySelectorAll('.account-container');
  24.  
  25. accountContainers.forEach(container => {
  26. // Select the questions and answers counts based on their position
  27. const questions = container.querySelector('.account-stat:nth-last-child(3) .account-number');
  28. const answers = container.querySelector('.account-stat:nth-last-child(2) .account-number');
  29.  
  30. // Check if the questions or answers count is greater than 0 and apply the highlight
  31. if ((questions && parseInt(questions.textContent, 10) > 0) ||
  32. (answers && parseInt(answers.textContent, 10) > 0)) {
  33. container.style.cssText = highlightStyle;
  34. }
  35. else{
  36. // container.style.cssText = highlightStyle;
  37. }
  38. });
  39. }
  40.  
  41. // Run the highlight function
  42. highlightIfActive();
  43. })();