Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

javascript - How to hide certain elements using Greasemonkey?

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

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

Or images like this:

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


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.

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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 ();
}

This gets both static and AJAX-loaded instances.

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

Reference:


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...