Revert StackExchange Formatting

Brings back the old line-height, colors, padding, borders, etc. of StackExchange websites like StackOverflow, SuperUser, ServerFault, etc.

Versione datata 01/09/2020. Vedi la nuova versione l'ultima versione.

  1. // ==UserScript==
  2. // @name Revert StackExchange Formatting
  3. // @namespace https://github.com/Prid13/Revert-StackExchange-Formatting
  4. // @version 1.1.0
  5. // @history 1.1.0 fully implemented old paragraph spacing
  6. // @history 1.0.8 added old compact paragraph spacing (margin-bottom)
  7. // @history 1.0.5 fixed bug: first line in code blocks being indented
  8. // @description Brings back the old line-height, colors, padding, borders, etc. of StackExchange websites like StackOverflow, SuperUser, ServerFault, etc.
  9. // @author Prid
  10. // @include /^https://(?:[^/]+\.)?(?:(?:stackoverflow|serverfault|superuser|stackexchange|askubuntu|stackapps)\.com|mathoverflow\.net)//
  11. // @run-at document-start
  12. // @grant none
  13. // ==/UserScript==
  14.  
  15. (function() {
  16. 'use strict';
  17.  
  18. var style = "";
  19.  
  20. var values = {
  21. line_height: 1.3,
  22. paragraph_spacing: "15px",
  23.  
  24. code_block_bgcol: "#eff0f1",
  25. code_block_padding: "12px 8px",
  26. code_block_radius: "3px",
  27.  
  28. inline_code_bgcol: "#e4e6e8",
  29. inline_code_padding: "1px 5px",
  30. inline_code_radius: "0px",
  31.  
  32. comment_code_bgcol: "#eff0f1",
  33. comment_code_padding: "1px 5px",
  34. };
  35.  
  36. buildCSS();
  37. injectCSS();
  38.  
  39. function buildCSS(){
  40. var line_height = values.line_height;
  41.  
  42. // paragraphs (revert line-height)
  43. style += ".s-prose { line-height: " + line_height + "!important; }";
  44. // OLD PARAGRAPH SPACING
  45. style += ".s-prose p, .s-prose ol, .s-prose ul, .s-prose blockquote, .s-prose hr { ";
  46. style += "margin-bottom: " + values.paragraph_spacing + "!important;"; // 15px
  47. style += "}";
  48. // margin-bottom for <pre>
  49. style += ".s-prose pre { ";
  50. style += "margin-bottom: " + "13px!important;";
  51. style += "}";
  52. // margin-bottom for ul li, ol li
  53. style += ".s-prose ol li, .s-prose ul li { ";
  54. style += "margin-bottom: " + "7.5px!important;";
  55. style += "}";
  56. // fix margin-bottom for last element in ol and ul
  57. style += ".s-prose ol li:last-child, .s-prose ul li:last-child { ";
  58. style += "margin-bottom: " + "0!important;";
  59. style += "}";
  60. // heading margin-bottom
  61. style += ".s-prose h1 { margin-bottom: 21px!important; }";
  62. style += ".s-prose h2 { margin-bottom: 19px!important; }";
  63. style += ".s-prose h3 { margin-bottom: 17px!important; }";
  64. style += ".s-prose h4 { margin-bottom: 15px!important; }";
  65. // fix margin-bottom for last element in blockquote
  66. style += ".s-prose blockquote *:last-child { ";
  67. style += "margin-bottom: " + "0!important;"; // don't apply to blockquotes
  68. style += "}";
  69.  
  70. // ADDITIONAL REVERSIONS
  71. // code blocks
  72. style += ".s-prose pre:not(.s-code-block) { ";
  73. style += "line-height: " + line_height + "!important;";
  74. style += "background-color: " + values.code_block_bgcol + "!important;";
  75. style += "padding: " + values.code_block_padding + "!important;";
  76. style += "border-radius: " + values.code_block_radius + "!important;";
  77. style += "}";
  78.  
  79. // fix inline code styling overriding code blocks (add transparent bg, remove padding)
  80. style += ".s-prose pre:not(.s-code-block) code { ";
  81. style += "background-color: transparent!important;";
  82. style += "padding: 0!important;";
  83. style += "}";
  84.  
  85. // inline code
  86. style += ".s-prose code:not(.s-code-block) {";
  87. style += "background-color: " + values.inline_code_bgcol + "!important;";
  88. style += "padding: " + values.inline_code_padding + "!important;";
  89. style += "border-radius: " + values.inline_code_radius + "!important;";
  90. style += "}";
  91.  
  92. // comment inline code
  93. style += ".comment-text code {";
  94. style += "background-color: " + values.comment_code_bgcol + "!important;";
  95. style += "padding: " + values.comment_code_padding + "!important;"; // padding is same
  96. style += "}";
  97.  
  98. }
  99.  
  100. function injectCSS(){
  101. // credit: https://stackoverflow.com/a/13436780/3705191
  102. var cssStyle = document.createElement('style');
  103. cssStyle.type = 'text/css';
  104. var rules = document.createTextNode(style);
  105. cssStyle.appendChild(rules);
  106. document.getElementsByTagName("head")[0].appendChild(cssStyle);
  107. }
  108. })();