对于此类问题,请发布指向目标页面的链接。或者,如果确实不可能,则将页面保存到pastebin.com并链接到该页面。
无论如何,使用jQuery contains()选择器对您问题的一般 答案并不难。这样的事情会起作用:
// ==Userscript==// @name _Remove annoying divs// @include http://YOUR_SERVER/YOUR_PATHvar badDivs = $("div div:contains('Annoying text, CASE SENSITIVE')");badDivs.remove ();//-- Or use badDivs.hide(); to just hide the content.更新新澄清的问题/代码:
在您的特定示例中,您将使用以下代码:
var badDivs = $("div.entry div.foo:contains('Yes')");badDivs.parent ().remove ();更新注释中指定的站点:
请注意,无需搜索文本,因为该站点方便地为键div提供了
isHot或类
notHot。
// ==Userscript==// @name _Unless they're hot, they're not (shown).// @include http://www.ratemyprofessors.com/SelectTeacher.jsp*// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js// @grant GM_addStyle// ==/Userscript==//- The @grant directive is needed to restore the proper sandbox.var badDivs = $("#ratingTable div.entry").has ("div.notHot");badDivs.remove ();最后,对于动态(AJAX驱动)页面,
使用
MutationObserver或
waitForKeyElements。(WaitForKeyElements在静态页面上也可以正常工作。)
这是将上面的脚本重写为AJAX感知的:
// ==Userscript==// @name _Unless they're hot, they're not (shown).// @include http://www.ratemyprofessors.com/SelectTeacher.jsp*// @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js// @require https://gist.github.com/raw/2625891/waitForKeyElements.js// @grant GM_addStyle// ==/Userscript==//- The @grant directive is needed to restore the proper sandbox.waitForKeyElements ("#ratingTable div.entry", deleteNotHot);function deleteNotHot (jNode) { if (jNode.has("div.notHot").length) { jNode.remove (); }}


