我不知道我在说什么,我走了。
在某些页面上,它会过滤它们,而其他页面(如 Youtube 评论)则不起作用。需要更改哪些代码才能在这些站点中工作?
// ==UserScript==
// @name profanity_filter
// @namespace localhost
// @description Profanity filter
// @include *
// @version 1
// @grant none
// ==/UserScript==
function recursiveFindTextNodes(ele) {
var result = [];
result = findTextNodes(ele,result);
return result;
}
function findTextNodes(current,result) {
for(var i = 0; i < current.childNodes.length; i++) {
var child = current.childNodes[i];
if(child.nodeType == 3) {
result.push(child);
}
else {
result = findTextNodes(child,result);
}
}
return result;
}
var l = recursiveFindTextNodes(document.body);
for(var i = 0; i < l.length; i++) {
var t = l[i].nodeValue;
t = t.replace(/badword1|badword2|badword3/gi, "****");
t = t.replace(/badword4/gi, "******");
t = t.replace(/badword5|badword6|badword7/gi, "*****");
t = t.replace(/badword8/gi, "******");
l[i].nodeValue = t;
}
*将代码中的亵渎替换为badword