StackExchange hide closed questions

Hide closed questions on the home page and in other lists of questions. Put a link showing the number of closed questions that have been hidden that shows the closed questions again.

As of 2021-11-03. See the latest version.

  1. // ==UserScript==
  2. // @name StackExchange hide closed questions
  3. // @namespace http://ostermiller.org/
  4. // @version 1.12
  5. // @description Hide closed questions on the home page and in other lists of questions. Put a link showing the number of closed questions that have been hidden that shows the closed questions again.
  6. // @include /https?\:\/\/([a-z\.]*\.)?(stackexchange|askubuntu|superuser|serverfault|stackoverflow|answers\.onstartups)\.com\/.*/
  7. // @exclude *://chat.stackoverflow.com/*
  8. // @exclude *://chat.stackexchange.com/*
  9. // @exclude *://chat.*.stackexchange.com/*
  10. // @exclude *://api.*.stackexchange.com/*
  11. // @exclude *://data.stackexchange.com/*
  12. // @grant unsafeWindow
  13. // ==/UserScript==
  14. (function() {
  15. 'use strict'
  16. var $ = unsafeWindow.jQuery
  17.  
  18. function closedQuestionVisibility(show){
  19.  
  20. var numberOfClosed=0;
  21. $('.question-summary').each(function(){
  22. var e = $(this)
  23. var t = e.find('h3 a').text()
  24. if (t.match(/ \[(migrated|closed|duplicate)\]$/)){
  25. e.addClass('closed').toggle(show)
  26. numberOfClosed++
  27. }
  28. });
  29. return numberOfClosed
  30. }
  31.  
  32. function run(){
  33. if ($('.question-summary').length){ // if it has a list of questions
  34. var numberHidden=closedQuestionVisibility(false)
  35. if (numberHidden > 0){
  36. $('#mainbar h1').after(" <a href='#' id='unhideclosedlink'>(" + numberHidden + " hidden closed)</a>")
  37. $('#unhideclosedlink').click(function(){
  38. closedQuestionVisibility(true)
  39. $('#unhideclosedlink').hide()
  40. return false;
  41. });
  42. $('html > head').append("<style>.question-summary.closed .status * { text-decoration: line-through; }</style>")
  43. }
  44. }
  45. }
  46.  
  47. run()
  48.  
  49. $('.page-numbers').click(function(){
  50. setTimeout(run, 2000);
  51. })
  52. })()