NGA+

NGA 增强(隐藏未关注子版的帖子)

  1. // ==UserScript==
  2. // @name NGA+
  3. // @namespace NGA+@Byzod
  4. // @description NGA 增强(隐藏未关注子版的帖子)
  5. // @include http://bbs.ngacn.cc/*
  6. // @include http://nga.178.com/*
  7. // @include http://bbs.nga.cn/*
  8. // @include http://club.178.com/*
  9. // @include http://bbs.bigccq.cn/*
  10. // @version 2
  11. // @license WTFPL version 2 or later version; http://www.wtfpl.net/about/
  12. // @grant none
  13. // jshint esversion:6
  14. // ==/UserScript==
  15.  
  16. function NGAPlus(){
  17. 'use strict';
  18. var self = this;
  19. // var uncheckedSubForumUrls = [];
  20. // 关注子论坛url列表
  21. var checkedSubForumUrls = [];
  22. // 获取已关注子论坛url列表
  23. this.GetUncheckedSubForumUrls = function(){
  24. var subForums = document.querySelectorAll("#sub_forums .b");
  25. subForums.forEach(
  26. (subForum) => {
  27. let subForumCheckbox = subForum.querySelector("input");
  28. let subForumUrl = subForum.querySelector("a");
  29. if(subForumCheckbox && subForumUrl && subForumCheckbox.checked === true){
  30. checkedSubForumUrls.push(subForumUrl.href);
  31. }
  32. }
  33. );
  34. // console.log("[NGA+]: 关注sub: " + checkedSubForumUrls.length + "个; 列表: %o", checkedSubForumUrls); // DEBUG
  35. };
  36. // 屏蔽未关注合集贴
  37. this.BanSubForumPosts = function(topicTable){
  38. var posts = topicTable.querySelectorAll(".topicrow");
  39. posts.forEach(
  40. (post) => {
  41. let titleadd2 = post.querySelector(".titleadd2>a");
  42. if(titleadd2 && !checkedSubForumUrls.includes(titleadd2.href)){
  43. post.hidden = true;
  44. }
  45. }
  46. );
  47. };
  48. // 注册屏蔽未关注合集贴事件
  49. this.RegisterBanSubForumsHandler = function(){
  50. var observeTarget = document.querySelector("#topicrows");
  51. var observer = new MutationObserver(
  52. ()=>{
  53. self.BanSubForumPosts(observeTarget);
  54. }
  55. );
  56. var config = { childList: true };
  57. if(observeTarget){
  58. observer.observe(observeTarget, config);
  59. }
  60. // 先来一发
  61. self.BanSubForumPosts(observeTarget);
  62. };
  63. // BOOM!
  64. this.Boom = function(){
  65. self.GetUncheckedSubForumUrls();
  66. self.RegisterBanSubForumsHandler();
  67. };
  68. }
  69.  
  70. var ngaBoom = new NGAPlus();
  71. ngaBoom.Boom();