如果没有使用Greasemonkey的id,我将如何删除DIV

How would I remove a DIV if there are no IDs using Greasemonkey?

本文关键字:何删除 删除 DIV Greasemonkey id 如果没有      更新时间:2023-09-26

我想从页面中删除两个<div>(隐藏和折叠空间)。

我最初打算使用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&amp;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&amp;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来查找不需要的内容。

列出坏框架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>');
}