Library for e-mail forward highlighting

Enable user scripts to highlight forwarded e-mails

此脚本不应直接安装,它是一个供其他脚本使用的外部库。如果您需要使用该库,请在脚本元属性加入:// @require https://update.cn-greasyfork.org/scripts/40782/265774/Library%20for%20e-mail%20forward%20highlighting.js

  1. function addStyles() {
  2. if (document.getElementById("email-quotes")) {
  3. console.log("Styles for e-mail quote highlighting already added, doing nothing");
  4. return;
  5. }
  6. console.log("Adding styles for e-mail quote highlighting");
  7. var styleNode = document.createElement('style');
  8. styleNode.setAttribute("type", "text/css");
  9. styleNode.id = "email-quotes";
  10. styleNode.innerHTML =
  11. 'mark.quote1 { background: #eee }\n' +
  12. 'mark.quote2 { background: #eef }\n' +
  13. 'mark.quote3 { background: #efe }\n' +
  14. 'mark.quote4 { background: #fee }\n' +
  15. 'mark.quote5 { background: #ddd }\n' +
  16. 'mark.quote6 { background: #ddf }\n' +
  17. 'mark.quote7 { background: #dfd }\n' +
  18. 'mark.quote8 { background: #fdd }\n';
  19. document.body.appendChild(styleNode);
  20. }
  21.  
  22. function highlightQuotes() {
  23. addStyles();
  24. if (
  25. document.getElementsByClassName("quote1").length ||
  26. document.getElementsByClassName("quote2").length ||
  27. document.getElementsByClassName("quote3").length ||
  28. document.getElementsByClassName("quote4").length ||
  29. document.getElementsByClassName("quote5").length ||
  30. document.getElementsByClassName("quote6").length ||
  31. document.getElementsByClassName("quote7").length ||
  32. document.getElementsByClassName("quote8").length
  33. ) {
  34. console.log("E-mail quotes already highlighted, doing nothing");
  35. return;
  36. }
  37. console.log("Highlighting e-mail quotes");
  38. var context = document.querySelector("pre,blockquote,.Wordsection1,.MsoPlainText,body");
  39. var instance = new Mark(context);
  40. instance.markRegExp(/^(> *){1}([^>\n].*|)$/gm, {"className" : "quote1" });
  41. instance.markRegExp(/^(> *){2}([^>\n].*|)$/gm, {"className" : "quote2" });
  42. instance.markRegExp(/^(> *){3}([^>\n].*|)$/gm, {"className" : "quote3" });
  43. instance.markRegExp(/^(> *){4}([^>\n].*|)$/gm, {"className" : "quote4" });
  44. instance.markRegExp(/^(> *){5}([^>\n].*|)$/gm, {"className" : "quote5" });
  45. instance.markRegExp(/^(> *){6}([^>\n].*|)$/gm, {"className" : "quote6" });
  46. instance.markRegExp(/^(> *){7}([^>\n].*|)$/gm, {"className" : "quote7" });
  47. instance.markRegExp(/^(> *){8,}([^>\n].*|)$/gm, {"className" : "quote8" });
  48. }