我在歌剧中写了一个论坛用户 - “禁止”javascript作为用户脚本(附加到每个网站),这使得不受欢迎的用户的帖子在我的计算机上不可见。
if (document.location.href.indexOf("wbsite.com/name.html") != -1)
{
Wortliste=['Persona non grata 1','Persona non grata 2'];
TagListe=document.selectNodes("//tr");
for (var Durchgehen=TagListe.length-1; Durchgehen>=0; Durchgehen--) {
if (IstVorhanden(TagListe[Durchgehen].innerHTML, Wortliste)) {
TagListe[Durchgehen].innerHTML = '';
}
}
}
function IstVorhanden(TagListeElement, Wortliste)
{
for(var Durchgehen = Wortliste.length - 1; Durchgehen>=0; Durchgehen--)
{
if(TagListeElement.indexOf(Wortliste[Durchgehen]) != -1)
return true;
}
return false;
}
据我了解,此代码遍历每个节点,检查节点是否包含不需要的人名,并用''替换此区域。
这适用于
<div class = "outside">
<div class = "inside">Persona non grata 1
</div>
<div class = "text">Undesired text
</div>
</div>
或
<div class = "outside">
<div class = "inside">Persona non grata 1
<div class = "text">Undesired text
</div>
</div>
</div>
但不是
<div class = "outside">
<div class = "inside">Persona grata: "I disagree with the statement of Persona non grata 1"
</div>
</div>
或
<div class = "outside">
<div class = "inside">Persona grata: [quote="Persona non grata 1"]Some text[/quote]
</div>
</div>
或
<div class = "outside">
<div class = "inside">Persona non grata 1
</div>
</div>
<div class = "outside2">
<div class = "text">Text from Persona non grata 1
</div>
</div>
将TagListe=document.selectNodes("//tr");
替换为TagListe=document.selectNodes("//div[starts-with(@class,'outside')]");
。
如何只使用前两种情况?