Tieba Keyword Filter

依關鍵字摺疊樓層廣告

目前為 2016-11-07 提交的版本,檢視 最新版本

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

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

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

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

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

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

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

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

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

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

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

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

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

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

// ==UserScript==
// @name        Tieba Keyword Filter
// @namespace   eight04.blogspot.com
// @description 依關鍵字摺疊樓層廣告
// @include     http://tieba.baidu.com/*
// @version     0.1.0
// @grant       GM_addStyle
// @grant		GM_registerMenuCommand
// @grant		GM_getValue
// @grant		GM_setValue
// @require https://greasyfork.org/scripts/7212-gm-config-eight-s-version/code/GM_config%20(eight's%20version).js?version=156587
// ==/UserScript==

var keywords;

GM_config.setup(
	{
		keywords: {
			label: "關鍵字(一行一個)",
			type: "textarea",
			default: "jiaoyimao.com/goods\n广告"
		}
	},
	function(){
		keywords = GM_config.get("keywords").split("\n");
	}
);

GM_addStyle(".tkf-hidden{height: 10px; overflow:hidden;} #j_p_postlist > div:not(.l_post):not(#j_p_postlist){display:none;} #thread_list > li:not(.thread_top_list_folder):not(.j_thread_list){display: none;}");

function toggle() {
	this.classList.toggle("tkf-hidden");
}

function hide() {
	var posts = document.querySelectorAll(".l_post");

	for (let post of posts) {
		for (let keyword of keywords) {
			if (post.textContent.includes(keyword)) {
				post.classList.add("tkf-hidden");
				post.addEventListener("click", toggle);
				break;
			}
		}
	}
}

hide();

new MutationObserver(hide).observe(
	document.querySelector("#j_p_postlist"),
	{
		childList: true
	}
);