MCPcopy Index your code
hub / github.com/XIU2/UserScript / filterComment

Function filterComment

Zhihu-Enhanced.user.js:1007–1021  ·  view source on GitHub ↗
(comment)

Source from the content-addressed store, hash-verified

1005
1006 function blockKeywords_comment() {
1007 function filterComment(comment) {
1008 let content = comment.querySelector('.CommentContent'); // 寻找评论文字所在元素
1009 let text = content.textContent.toLowerCase(); // 全部转为小写(用来不区分大小写)
1010 content.querySelectorAll('img.sticker[alt]').forEach((img)=>{text += img.alt}) // 将评论中的表情添加到待遍历的评论文字中
1011
1012 let keywords = menu_value('menu_customBlockKeywords');
1013 for (const keyword of keywords) { // 遍历关键词黑名单
1014 if (keyword != '' && text.indexOf(keyword.toLowerCase()) > -1) { // 找到就删除该评论
1015 console.log('已屏蔽评论:' + text);
1016 content.dataset.text = content.innerHTML
1017 content.onclick = (e)=>{if (e.target.dataset.text) {e.target.innerHTML = e.target.dataset.text;e.target.removeAttribute('data-text');}}
1018 content.textContent = '[该评论已屏蔽,可点击显示]';
1019 }
1020 }
1021 }
1022
1023 const callback = (mutationsList, observer) => {
1024 for (const mutation of mutationsList) {

Callers 1

callbackFunction · 0.85

Calls 1

menu_valueFunction · 0.70

Tested by

no test coverage detected