StackOverflow: Highlight Your Text

This userscript highlights the questions, answers, and comments you've made on StackOverflow and StackExchange to distinguish you from other users.

  1. // ==UserScript==
  2. // @name StackOverflow: Highlight Your Text
  3. // @namespace DanKaplanSES
  4. // @version 0.2
  5. // @description This userscript highlights the questions, answers, and comments you've made on StackOverflow and StackExchange to distinguish you from other users.
  6. // @author DanKaplanSES
  7. // @match https://*.stackoverflow.com/questions/*
  8. // @match https://*.superuser.com/questions/*
  9. // @match https://*.stackexchange.com/questions/*
  10. // @match https://*.serverfault.com/questions/*
  11. // @match https://*.askubuntu.com/questions/*
  12. // @match https://*.stackapps.com/questions/*
  13. // @match https://*.mathoverflow.net/questions/*
  14. // @icon https://www.google.com/s2/favicons?sz=64&domain=stackoverflow.com
  15. // @require https://cdnjs.cloudflare.com/ajax/libs/jquery/3.7.1/jquery.min.js
  16. // @grant none
  17. // @license MIT
  18. // @supportURL https://github.com/DanKaplanSES
  19. // ==/UserScript==
  20.  
  21. // Not used, but helpful information for https://webaim.org/resources/contrastchecker/
  22. const darkBackgroundColor = `#252627`;
  23. const lightBackgroundColor = `#FFFFFF`;
  24.  
  25. jQuery.noConflict(true)(function($) {
  26. setTimeout(() => {
  27. const isDarkTheme = $(`.theme-dark`).length > 0;
  28. const highlightColor = isDarkTheme ? `#FFA953` : `#A8681A`; // Change this line for custom colors
  29.  
  30. const userCardSelector = `a.s-user-card`;
  31. const userHref = $(userCardSelector)?.attr("href");
  32. if (userHref === undefined || userHref === null) {
  33. console.info(`The "Color Code Your Text" userscript could not find an href attribute with this CSS selector: '${userCardSelector}'. Exiting early.`);
  34. console.info(`Possible cause: you are not logged in.`);
  35. return;
  36. }
  37. const linkSelector = `*[href="${userHref}"]`;
  38.  
  39. $(`#content`).find(linkSelector).each(function () {
  40. $(this).parents(`.postcell, .answercell`).find($(`.s-prose`)).each(function () {
  41. $(this).css({ "color": highlightColor });
  42. $(this).find(`blockquote`).css({ "color": highlightColor });
  43. $(this).find(`code`).css({ "color": highlightColor });
  44. });
  45.  
  46. $(this).parents(`.comment-body`).find(`.comment-copy`).each(function () {
  47. $(this).css({ "color": highlightColor });
  48. $(this).find(`blockquote`).css({ "color": highlightColor });
  49. $(this).find(`code`).css({ "color": highlightColor });
  50. });
  51. });
  52.  
  53. }, 500);
  54. });