Skip to content

Commit 0a66ee5

Browse files
committed
新增 评论区中 [屏蔽关键词] 后可点击恢复显示;
修复 评论区 [屏蔽用户]、[屏蔽关键词] 失效的问题
1 parent ede0f6f commit 0a66ee5

1 file changed

Lines changed: 39 additions & 30 deletions

File tree

Zhihu-Enhanced.user.js

Lines changed: 39 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// @name:zh-CN 知乎增强
44
// @name:zh-TW 知乎增強
55
// @name:en Zhihu enhancement
6-
// @version 2.3.3
6+
// @version 2.3.4
77
// @author X.I.U
88
// @description 屏蔽首页视频、默认收起回答、快捷收起回答/评论(左键两侧)、快捷回到顶部(右键两侧)、屏蔽用户、屏蔽关键词、移除高亮链接、屏蔽盐选内容/热榜杂项、净化搜索热门、净化标题消息、展开问题描述、显示问题作者、默认高清原图(无水印)、置顶显示时间、完整问题时间、区分问题文章、直达问题按钮、默认站外直链...
99
// @description:zh-TW 屏蔽首頁視頻、默認收起回答、快捷收起回答/評論、快捷回到頂部、屏蔽用戶、屏蔽關鍵詞、移除高亮鏈接、屏蔽鹽選內容、淨化搜索熱門、淨化標題消息、默認高清原圖(無水印)、置頂顯示時間、完整問題時間、區分問題文章、默認站外直鏈...
@@ -454,7 +454,7 @@ function blockUsers(type) {
454454
break;
455455
}
456456
blockUsers_comment(); // 评论区
457-
blockUsers_button(); // 加入黑名单按钮
457+
blockUsers_button(); // 加入黑名单按钮(用户信息悬浮框中)
458458

459459
function blockUsers_(className1, className2) {
460460
// 前几条因为是直接加载的,而不是动态插入网页的,所以需要单独判断
@@ -613,18 +613,20 @@ function blockUsers(type) {
613613
for (const mutation of mutationsList) {
614614
for (const target of mutation.addedNodes) {
615615
if (target.nodeType != 1) return
616-
let item = target.querySelector('img.Avatar[width="24"]')
617-
if (item) {
618-
//console.log(item)
619-
menu_value('menu_customBlockUsers').forEach(function(item1){ // 遍历用户黑名单
620-
//console.log(item.alt,item1)
621-
if (item.alt === item1) { // 找到就删除该搜索结果
622-
item.parentElement.parentElement.style.display = "none";
623-
}
624-
})
616+
//console.log(target)
617+
if (target.tagName == 'DIV' && target.className.indexOf('css-') == 0 && target.dataset.id == undefined) {
618+
let item = target.querySelector('a[href^="https://www.zhihu.com/people/"]>img.Avatar[alt][loading]')
619+
if (item) {
620+
//console.log(item)
621+
menu_value('menu_customBlockUsers').forEach(function(item1){ // 遍历用户黑名单
622+
if (item.alt === item1) { // 找到就删除该搜索结果
623+
//console.log(item.alt,item1)
624+
item.parentElement.parentElement.parentElement.parentElement.style.display = "none";
625+
}
626+
})
625627

626-
// 添加屏蔽用户按钮(点赞、回复等按钮后面)
627-
/*if (item) {
628+
// 添加屏蔽用户按钮(点赞、回复等按钮后面)
629+
/*if (item) {
628630
let footer = findParentElement(item, 'CommentItemV2-meta', true).parentElement.querySelector('.CommentItemV2-metaSibling > .CommentItemV2-footer'),
629631
userid = item.parentElement;
630632
if (userid && footer && !footer.lastElementChild.dataset.name) {
@@ -633,6 +635,7 @@ function blockUsers(type) {
633635
footer.lastElementChild.onclick = function(){blockUsers_button_add(this.dataset.name, this.dataset.userid, false)}
634636
}
635637
}*/
638+
}
636639
}
637640
}
638641
}
@@ -844,23 +847,17 @@ function blockKeywords(type) {
844847

845848
function blockKeywords_comment() {
846849
function filterComment(comment) {
847-
let content = comment.querySelector('.RichText'); // 寻找评论文字所在元素
848-
let texts = [content.textContent.toLowerCase()]; // 因为要针对评论中的表情,所以需要整个数组并全部转为小写(用来不区分大小写)
849-
for (let i = 0; i < content.children.length; i++) { // 该条针对的是评论中的表情
850-
let emoticonValue = content.children[i].getAttribute('data-zhihu-emoticon'); // 确定是表情就将其添加到稍后遍历的数组中
851-
if (emoticonValue) {
852-
texts.push(emoticonValue)
853-
}
854-
}
850+
let content = comment.querySelector('.CommentContent'); // 寻找评论文字所在元素
851+
let text = content.textContent.toLowerCase(); // 全部转为小写(用来不区分大小写)
852+
content.querySelectorAll('img.sticker[alt]').forEach((img)=>{text += img.alt}) // 将评论中的表情添加到待遍历的评论文字中
855853

856854
let keywords = menu_value('menu_customBlockKeywords');
857-
for (const text of texts) {
858-
for (const keyword of keywords) { // 遍历关键词黑名单
859-
if (keyword != '' && text.indexOf(keyword.toLowerCase()) > -1) { // 找到就删除该评论
860-
console.log('已屏蔽评论:' + text);
861-
content.textContent = '[该评论已屏蔽]';
862-
break;
863-
}
855+
for (const keyword of keywords) { // 遍历关键词黑名单
856+
if (keyword != '' && text.indexOf(keyword.toLowerCase()) > -1) { // 找到就删除该评论
857+
console.log('已屏蔽评论:' + text);
858+
content.dataset.text = content.innerHTML
859+
content.onclick = (e)=>{if (e.target.dataset.text) {e.target.innerHTML = e.target.dataset.text;e.target.removeAttribute('data-text');}}
860+
content.textContent = '[该评论已屏蔽,可点击显示]';
864861
}
865862
}
866863
}
@@ -869,9 +866,21 @@ function blockKeywords(type) {
869866
for (const mutation of mutationsList) {
870867
for (const target of mutation.addedNodes) {
871868
if (target.nodeType != 1) return
872-
for (const node of target.querySelectorAll('*')) {
873-
if (node.className === 'CommentItemV2-metaSibling') filterComment(node);
869+
//console.log(target);
870+
if (target.tagName == 'DIV' && target.className.indexOf('css-') == 0 && target.dataset.id == undefined) {
871+
let item = target.querySelector('a[href^="https://www.zhihu.com/people/"]>img.Avatar[alt][loading]')
872+
if (item) {
873+
//console.log(item)
874+
filterComment(item.parentElement.parentElement.parentElement.parentElement)
875+
}
874876
}
877+
878+
/*if (target.tagName == 'DIV' && target.dataset.id !== undefined) {
879+
console.log(target);
880+
for (const node of target.querySelectorAll('*')) {
881+
if (node.className === 'CommentItemV2-metaSibling') filterComment(node);
882+
}
883+
}*/
875884
}
876885
}
877886
};

0 commit comments

Comments
 (0)