栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何使用greasemonkey有选择地从网站中删除内容

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何使用greasemonkey有选择地从网站中删除内容

对于此类问题,请发布指向目标页面的链接。或者,如果确实不可能,则将页面保存到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 ();    }}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/575305.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号