StackExchange Tweaks

Minor visual tweaks to StackExchange (remove the new sidebar from Q/A pages, for classic look)

  1. // ==UserScript==
  2. // @name StackExchange Tweaks
  3. // @namespace SET
  4. // @description Minor visual tweaks to StackExchange (remove the new sidebar from Q/A pages, for classic look)
  5. // @version 1.1.0
  6. // @license MIT
  7. // @include https://stackoverflow.com/*
  8. // @include https://*.stackoverflow.com/*
  9. // @include https://superuser.com/*
  10. // @include https://serverfault.com/*
  11. // @include https://*.stackexchange.com/*
  12. // @include https://askubuntu.com/*
  13. // @include https://mathoverflow.net/*
  14. // @include https://stackapps.com/*
  15. // @run-at document-start
  16. // @grant GM_addStyle
  17. // ==/UserScript==
  18.  
  19. // ==Options==
  20.  
  21. // Swap the positions of the notifications block and the username/stats block
  22. // in the header
  23. //
  24. // This pushes the user profile off towards the corner, and brings the action
  25. // buttons closer to the center
  26. //
  27. var swapProfileAndButtons = true;
  28.  
  29. // Hide the 2018 sidebar when we are on question pages (reduces visual noise)
  30. //
  31. var hideSidebarOnQuestionPages = true;
  32.  
  33. // If you don't like things to be 3D when they don't need to be
  34. //
  35. var noShadows = true;
  36.  
  37. // Lighten the new stats above the question, if you find them distracting
  38. //
  39. var deemphasiseStats = true;
  40.  
  41. // Ensure we can see which questions we have already viewed in the past
  42. //
  43. var makeVisitedLinksClearer = true;
  44.  
  45. // ==/Options==
  46.  
  47. if (swapProfileAndButtons) {
  48. //var secondaryNav = document.querySelector('.secondary-nav')
  49. //secondaryNav.parentNode.insertBefore(secondaryNav, secondaryNav.parentNode.firstChild)
  50. var profileElementInner = document.querySelector('.my-profile');
  51. if (profileElementInner) {
  52. var profileElementContainer = profileElementInner.parentNode;
  53. profileElementContainer.parentNode.appendChild(profileElementContainer);
  54. } else {
  55. console.warn("Could not find .my-profile element");
  56. }
  57. }
  58.  
  59. if (hideSidebarOnQuestionPages) {
  60. if (document.location.pathname.match(/^\/(q|questions)\//)) {
  61. GM_addStyle('#left-sidebar { display: none; }');
  62. // On some sites this leaves an unnecessary line down the left of the content, which we can remove.
  63. // But on some sites, the lines is an all sides, so we don't want to remove it!
  64. /*
  65. if (document.location.hostname.match(/^(stackoverflow.com|(politics|physics|earthscience).stackexchange.com)$/)) {
  66. GM_addStyle('#content { border-left: none; }');
  67. }
  68. */
  69. // General purpose solution: do on the left whatever the right is doing.
  70. const contentElem = document.querySelector('#content');
  71. if (contentElem) {
  72. contentElem.style.borderLeft = getComputedStyle(contentElem)['border-right'] || 'none';
  73. }
  74. }
  75. }
  76.  
  77. if (noShadows) {
  78. // The "Featured on Meta" box on the right, above "Related" and "Hot Network Questions"
  79. GM_addStyle('.s-sidebarwidget { box-shadow: none; }');
  80. }
  81.  
  82. if (deemphasiseStats) {
  83. // There isn't a clear ID or class for the stats, so I used this monstrosity
  84. GM_addStyle('#question-header + .grid.fw-wrap.bb { opacity: 0.5; font-size: 0.9em; }');
  85. }
  86.  
  87. if (makeVisitedLinksClearer) {
  88. setTimeout(() => {
  89. // Because this needs to work on multiple websites, I opted for a classic dark magenta
  90. GM_addStyle('.question-hyperlink:visited, .answer-hyperlink:visited { color: #481691; }');
  91. // I thought it might be a problem that the links in the search results had params which were removed when we visited the page, but apparently that wasn't a problem.
  92. /*
  93. const links = document.querySelectorAll('a');
  94. for (const link of links) {
  95. link.href = link.href.replace(/r=SearchResults/, '').replace(/\?$/, '');
  96. }
  97. */
  98. }, 1000);
  99. }