如何使用Greasemonkey隐藏某些元素? [英] How to hide certain elements using Greasemonkey?

查看:164
本文介绍了如何使用Greasemonkey隐藏某些元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用Greasemonkey隐藏某些元素。这样的链接:

I'm looking to hide certain elements using Greasemonkey. Links like this:

<a href="earn-google-circles.php" target="_blank" );"="">View</a>

或者像这样的图片:

<img src="http://www.somesite.org/img/icon/earn-google-circles-435912.png" alt="Circle" title="Google Circle" height="18px" width="50px">



当然,它是较大Div的一部分,但是div不能被隐藏,因为它会隐藏其他我不想隐藏的东西。


Of course, it's a part of a larger Div, but that div can't be hidden because it would hide other things I don't want hidden.

那么,有没有办法使用Greasemonkey隐藏这些元素?

(编者注:也适用于Tampermonkey)

So, is there any way to hide these elements using Greasemonkey?
(Editor's note: also applies to Tampermonkey)

推荐答案

要隐藏所有 Google Circles 链接(或图像),请使用Greasemonkey / Tampermonkey脚本,如下所示:

To hide all manner of Google Circles links (or images), use a Greasemonkey/Tampermonkey script like this:

// ==UserScript==
// @name     _Hide annoying links
// @include  http://YOUR_SERVER.COM/YOUR_PATH/*
// @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 work around a design change
    introduced in GM 1.0.   It restores the sandbox.
*/
waitForKeyElements (
    "a[href*='earn-google-circles'], img[src*='earn-google-circles']",
    hideNode
);

function hideNode (jNode) {
    jNode.hide ();
}

这会同时获得静态和AJAX加载的实例

参见在AJAX驱动的网站上选择并激活正确的控件,以获取有关选择jQuery选择器的提示。

See Choosing and activating the right controls on an AJAX-driven site for tips on choosing a jQuery selector.

参考:

  • jQuery selectors
  • waitForKeyElements()
  • jQuery hide()

这篇关于如何使用Greasemonkey隐藏某些元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆