Greasy Fork is available in English.

Revert StackExchange Formatting

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

Verze ze dne 01. 09. 2020. Zobrazit nejnovější verzi.

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