javascript - 如果没有使用Greasemonkey的ID,我该如何删除DIV?

标签 javascript dom greasemonkey

我想从页面中删除两个<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>设计出可靠的选择器。

但是,如果它们始终包含具有src属性的iframe来包含不受欢迎的内容,那么您可以使用这些iframe来查找卑鄙的div。

在错误的iframe src属性中列出关键文本片段。
我还使用了jQuerywaitForKeyElements(),以防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/

相关文章:

javascript - 设置 Webpack 和 Babel 以转译/填充旧代码

javascript - 在另一个类中选择一个特定类并使用javascript从DOM获取内部html

javascript - Selenium:无法在 GWT App 中找到元素

javascript - 如何从 sfpg 中找到所有 img src 属性(单文件 PHP 库)

javascript - 如何使用jQuery根据菜单项将菜单项更改为其他颜色

c# - 将 System.DateTime 转换为 Javascript DateString

javascript - 什么是 "Uncaught TypeError: Cannot call method ' shift' of null - all.js :54 mean?

javascript - 可以附加很多事件监听器吗?

greasemonkey - setTimeout 在 Greasemonkey 中并不总是有效

javascript - Tampermonkey,Userscripts 使用 POP UP 将 URL 添加到脚本