Punctuation color

https://www.reddit.com/r/userscripts/comments/gnoji7/request_punctuation_color/

  1. // ==UserScript==
  2. // @name Punctuation color
  3. // @description https://www.reddit.com/r/userscripts/comments/gnoji7/request_punctuation_color/
  4. // @author Livadas
  5. // @include *
  6. // @require http://code.jquery.com/jquery-latest.js
  7. // @run-at document-idle
  8. // @version 2020-05-27
  9. // @namespace https://greasyfork.org/users/237051
  10. // ==/UserScript==
  11.  
  12. (function() {
  13.  
  14. function addGlobalStyle(css) {
  15. var head, style;
  16. head = document.getElementsByTagName('head')[0];
  17. if (!head) { return; }
  18. style = document.createElement('style');
  19. style.type = 'text/css';
  20. style.innerHTML = css;
  21. head.appendChild(style);
  22. }
  23.  
  24. addGlobalStyle(".highlightComa {color:red!important; background-color:white;}");
  25. addGlobalStyle(".highlightMdash {color:blue!important; background-color:white;}");
  26. addGlobalStyle(".highlightNdash {color:blue!important; background-color:white;}");
  27. addGlobalStyle(".highlightDoubleQuotes {color:green!important; background-color:white;}");
  28.  
  29. var docText = $('body')[0].innerHTML;
  30.  
  31. var modifiedText = docText.replace(/—/gi, "<span class='highlightMdash'>&mdash;</span>");
  32.  
  33. modifiedText = modifiedText.replace(/―/gi, "<span class='highlightMdash'>&horbar;</span>");
  34. modifiedText = modifiedText.replace(/,/gi, "<span class='highlightComa'>,</span>");
  35. modifiedText = modifiedText.replace(/‒/gi, "<span class='highlightNdash'>&ndash;</span>");
  36. modifiedText = modifiedText.replace(/–/gi, "<span class='highlightNdash'>&#8210;</span>");
  37. modifiedText = modifiedText.replace(/“/gi, "<span class='highlightDoubleQuotes'>“</span>");
  38. modifiedText = modifiedText.replace(/”/gi, "<span class='highlightDoubleQuotes'>”</span>");
  39.  
  40. $('body').html(modifiedText);
  41.  
  42. })();