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.

目前为 2017-06-16 提交的版本。查看 最新版本

  1. // ==UserScript==
  2. // @name StackExchange hide closed questions
  3. // @namespace http://ostermiller.org/
  4. // @version 1.10
  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\.com\/.*/
  7. // @include /https?\:\/\/([a-z\.]*\.)?askubuntu\.com\/.*/
  8. // @include /https?\:\/\/([a-z\.]*\.)?superuser\.com\/.*/
  9. // @include /https?\:\/\/([a-z\.]*\.)?serverfault\.com\/.*/
  10. // @include /https?\:\/\/([a-z\.]*\.)?stackoverflow\.com\/.*/
  11. // @include /https?\:\/\/([a-z\.]*\.)?answers.onstartups\.com\/.*/
  12. // @grant none
  13. // ==/UserScript==
  14. function closedQuestionVisibility(show){
  15. var numberOfClosed=0;
  16. $('.question-summary').each(function(){
  17. var e = $(this);
  18. var t = e.find('h3 a').text();
  19. if (t.match(/\]$/)){
  20. e.addClass('closed');
  21. if(show){
  22. e.show();
  23. } else {
  24. e.hide();
  25. }
  26. numberOfClosed++;
  27. }
  28. });
  29. return numberOfClosed;
  30. }
  31.  
  32. if (/\.com\/(questions)?([\?\#].*)?$/.exec(window.document.location.href)){ // only on pages with questions
  33. var numberHidden=closedQuestionVisibility(false);
  34. if (numberHidden > 0){
  35. $('#mainbar h1').append(" <a href='#' id='unhideclosedlink'>(" + numberHidden + " hidden closed)</a>");
  36. $('#unhideclosedlink').click(function(){
  37. closedQuestionVisibility(true);
  38. $('#unhideclosedlink').hide();
  39. return false;
  40. });
  41. $('html > head').append("<style>.question-summary.closed .status * { text-decoration: line-through; }</style>");
  42. }
  43. }