mirror of
https://github.com/XIU2/UserScript.git
synced 2026-09-22 15:06:57 +00:00
+50
-1
@@ -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,12 +1041,12 @@ function questionInvitation(){
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
(function() {
|
||||
addEventListener_DOMNodeInserted(); // 监听 网页插入元素 事件
|
||||
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) {
|
||||
|
||||
Reference in New Issue
Block a user