我想删除两个 <div>
页面中的 s(隐藏并折叠空间)。
我最初打算使用 Greasemonkey 并根据 ID 进行删除 - 但这些似乎没有 ID。 其次 - 我假设 iframe 的内容发生变化(因为这是内容横幅)。
我该如何让这些消失? :)
<div style="float: left; width: 700px; height:250px; margin-top:5px; margin-bottom:10px;">
<iframe src='http://www.therpf.com/banner-system/feature2.php' style='position:relative;top:0px;left:0px;height:272px;width:756px;' frameborder=0 scrolling='no'></iframe>
</div>
<div style="background: url('/images/styles/prometheus/black-30.png'); border:1px solid #333333; border-radius: 10px; float: right; margin-top:5px; margin-right: 2px; padding:10px 12px; width:300px; height: 250px;">
<!--Replica Movie Props – 9-->
<!--Screen Used Movie Props and Wardrobe - 45-->
<!--Replica Paper Props – 40-->
<!--Free Harry Paper Props – 64-->
<!--Sculpture and Makeup Effects – 62-->
<!--Replica Movie Costumes - 24-->
<!--Costume and Cosplay Showcase – 67-->
<!--Judge Dredd Costume Group – 71-->
<!--General Modeling - 11-->
<!--Studio Scale Models – 10-->
<!--Entertainment and Movie Talk – 47-->
<!--Conventions and Prop Parties – 68-->
<!--Off-Topic Talk – 12-->
<!--The Junkyard - 13-->
<iframe id='a9418415' name='a9418415' src='http://moviepropsites.com/ads/www/delivery/afr.php?zoneid=67&target=_blank' frameborder='0' scrolling='no' width='300' height='250'><a rel='nofollow' href='http://moviepropsites.com/ads/www/delivery/ck.php?n=a0516fad' target='_blank'><img src='http://moviepropsites.com/ads/www/delivery/avw.php?zoneid=67&n=a0516fad' border='0' alt='' /></a></iframe>
</div>
<div style="clear:both"></div>
基本上 - 我想删除两个主要的 DIV,然后用这个替换它。
<div style="clear:both"></div>
任何帮助将不胜感激。
====已更新====
其中一页上的完整输出。我已经把它粘贴到pastebin了。 http://pastebin.com/s50tM8iU
第 401-465 行是我试图删除的内容,仅保留第 465 行。
谢谢!
最佳答案
我们可能需要查看整个页面才能为 <div>
找出强大的选择器s。
但是,如果它们始终包含带有 src
的 iframe属性为不良内容,那么您可以使用这些 iframe 来追捕卑鄙的 div。
列出错误 iframe 中的关键文本片段 src
属性。
我也在使用jQuery和 waitForKeyElements()
,以防该内容是通过 AJAX 添加的。
所以,脚本看起来像这样:
// ==UserScript==
// @name _Remove bad divs containing bad iframes
// @include http://YOUR_SERVER.COM/YOUR_PATH/*
// @require http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js
// @require https://gist.github.com/raw/2625891/waitForKeyElements.js
// @grant GM_addStyle
// ==/UserScript==
/*- The @grant directive is needed to work around a design change
introduced in GM 1.0. It restores the sandbox.
*/
var badFrameSrcSnips = [
//-- These are case-sensitive
"therpf.com/banner-system",
"moviepropsites.com/ads"
];
for (var J in badFrameSrcSnips) {
var srcSnippet = badFrameSrcSnips[J];
waitForKeyElements (
"iframe[src*='" + srcSnippet + "']", removeBadDiv
);
}
function removeBadDiv (jNode) {
//-- Replace the bad div (iframe's parent) with a tame one.
jNode.parent ().replaceWith ('<div style="clear:both"></div>');
}
关于javascript - 如果没有使用 Greasemonkey 的 ID,我该如何删除 DIV?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17130419/