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.

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