NGA+

NGA 增强(隐藏已取消关注子版的帖子)

目前為 2017-05-21 提交的版本,檢視 最新版本

您需要先安裝使用者腳本管理器擴展,如 TampermonkeyGreasemonkeyViolentmonkey 之後才能安裝該腳本。

You will need to install an extension such as Tampermonkey to install this script.

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyViolentmonkey 後才能安裝該腳本。

您需要先安裝使用者腳本管理器擴充功能,如 TampermonkeyUserscripts 後才能安裝該腳本。

你需要先安裝一款使用者腳本管理器擴展,比如 Tampermonkey,才能安裝此腳本

您需要先安裝使用者腳本管理器擴充功能後才能安裝該腳本。

(我已經安裝了使用者腳本管理器,讓我安裝!)

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展,比如 Stylus,才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

你需要先安裝一款使用者樣式管理器擴展後才能安裝此樣式

(我已經安裝了使用者樣式管理器,讓我安裝!)

// ==UserScript==
// @name        NGA+
// @namespace   NGA+@Byzod
// @description NGA 增强(隐藏已取消关注子版的帖子)
// @include     http://bbs.ngacn.cc/*
// @include     http://nga.178.com/*
// @include     http://bbs.nga.cn/*
// @include     http://club.178.com/*
// @include     http://bbs.bigccq.cn/*
// @version     1
// @license     WTFPL version 2 or later version; http://www.wtfpl.net/about/
// @grant       none
// jshint esversion:6
// ==/UserScript==

function NGAPlus(){
	'use strict';
	var self = this;
	
	// 已取关子论坛url列表
	var uncheckedSubForumUrls = [];
	
	// 获取已取关子论坛url列表
	this.GetUncheckedSubForumUrls = function(){
		var subForums = document.querySelectorAll("#sub_forums .b");
		subForums.forEach(
			(subForum) => {
				let subForumCheckbox = subForum.querySelector("input");
				let subForumUrl = subForum.querySelector("a");
				if(subForumCheckbox && subForumUrl && subForumCheckbox.checked === false){
					uncheckedSubForumUrls.push(subForumUrl.href);
				}
			}
		);
	};
	
	// 屏蔽已取关合集贴
	this.BanSubForumPosts = function(topicTable){
		var posts = topicTable.querySelectorAll(".topicrow");
		posts.forEach(
			(post) => {
				let titleadd2 = post.querySelector(".titleadd2>a");
				if(titleadd2 && uncheckedSubForumUrls.indexOf(titleadd2.href) >= 0){
					post.hidden = true;
				}
			}
		);
	};
	
	// 注册屏蔽已取关合集贴事件
	this.RegisterBanSubForumsHandler = function(){
		var observeTarget = document.querySelector("#topicrows");
		var observer = new MutationObserver(
			()=>{
				self.BanSubForumPosts(observeTarget);
			}
		);
		var config = { childList: true };
		
		if(observeTarget){
			observer.observe(observeTarget, config);
		}
		// 先来一发
		self.BanSubForumPosts(observeTarget);
	};
	
	// BOOM!
	this.Boom = function(){
		self.GetUncheckedSubForumUrls();
		self.RegisterBanSubForumsHandler();
	};
}

var ngaBoom = new NGAPlus();
ngaBoom.Boom();