From 27ea4b73c69df80c7fa849b71f56a3de5e716226 Mon Sep 17 00:00:00 2001 From: Rcmcpe Date: Thu, 29 Jul 2021 23:07:40 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=B1=8F=E8=94=BD?= =?UTF-8?q?=E8=AF=84=E8=AE=BA=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zhihu-Enhanced.user.js | 51 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/Zhihu-Enhanced.user.js b/Zhihu-Enhanced.user.js index 28d0a1f78..6945eef24 100644 --- a/Zhihu-Enhanced.user.js +++ b/Zhihu-Enhanced.user.js @@ -483,6 +483,9 @@ function blockKeywords(type) { case 'search': blockKeywords_search(); break; + case 'comment': + blockKeywords_comment(); + break; } function blockKeywords_index_() { @@ -630,6 +633,52 @@ function blockKeywords(type) { } document.addEventListener('DOMNodeInserted', blockKeywords); // 监听插入事件 } + + + function blockKeywords_comment() { + function filterComment(comment) { + let content = comment.querySelector('.RichText'); + let texts = [content.textContent.toLowerCase()]; + for (let i = 0; i < content.children.length; i++) { + let emoticonValue = content.children[i].getAttribute('data-zhihu-emoticon'); + if (emoticonValue) { + texts.push(emoticonValue) + } + } + + let keywords = menu_value('menu_customBlockKeywords'); + for (const text of texts) { + for (const keyword of keywords) { // 遍历关键词黑名单 + if (text.indexOf(keyword.toLowerCase()) > -1) { // 找到就删除该信息流 + console.log(text); + content.textContent = '[已屏蔽]'; + break; + } + } + } + } + function blockKeywords(node) { + switch (node.className) { + case 'NestComment--rootComment': + case 'NestComment--child': + case 'CommentItemV2': + filterComment(node); + break; + } + } + + const callback = (mutationsList, observer) => { + for (const mutation of mutationsList) { + for (const target of mutation.addedNodes) { + for (const node of target.querySelectorAll('*')) { + blockKeywords(node); + } + } + } + }; + const observer = new MutationObserver(callback); + observer.observe(document, { childList: true, subtree: true }); + } } @@ -992,7 +1041,6 @@ function questionInvitation(){ }); } - (function() { addEventListener_DOMNodeInserted(); // 监听 网页插入元素 事件 questionInvitation(); // 默认折叠邀请 @@ -1007,6 +1055,7 @@ function questionInvitation(){ questionRichTextMore(); // 展开问题描述 blockUsers('question'); // 屏蔽指定用户 blockYanXuan(); // 屏蔽盐选内容 + blockKeywords('comment'); // 评论屏蔽指定关键词 } setInterval(topTime_question, 300); // 置顶显示时间 } else if (window.location.href.indexOf("search") > -1) { // 搜索结果页 // From 03f8f0234b4470c67feb0e7a60159e95cf4ad7a5 Mon Sep 17 00:00:00 2001 From: Rcmcpe Date: Thu, 29 Jul 2021 23:37:36 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E6=94=AF=E6=8C=81=E9=80=9A=E7=9F=A5?= =?UTF-8?q?=E7=AD=89=E5=85=B6=E4=BB=96=E5=9C=B0=E6=96=B9=E7=9A=84=E8=AF=84?= =?UTF-8?q?=E8=AE=BA=E5=B1=8F=E8=94=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Zhihu-Enhanced.user.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Zhihu-Enhanced.user.js b/Zhihu-Enhanced.user.js index 6945eef24..c3e1e6cff 100644 --- a/Zhihu-Enhanced.user.js +++ b/Zhihu-Enhanced.user.js @@ -1046,6 +1046,7 @@ function questionInvitation(){ questionInvitation(); // 默认折叠邀请 setInterval(originalPic,100); // 默认高清原图 if (menu_value('menu_directLink')) setInterval(directLink, 100); // 默认站外直链 + blockKeywords('comment'); // 评论屏蔽指定关键词 if (window.location.href.indexOf("question") > -1) { // 回答页 // if (window.location.href.indexOf("waiting") == -1) { @@ -1055,7 +1056,6 @@ function questionInvitation(){ questionRichTextMore(); // 展开问题描述 blockUsers('question'); // 屏蔽指定用户 blockYanXuan(); // 屏蔽盐选内容 - blockKeywords('comment'); // 评论屏蔽指定关键词 } setInterval(topTime_question, 300); // 置顶显示时间 } else if (window.location.href.indexOf("search") > -1) { // 搜索结果页 //