Revert StackExchange Formatting

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

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