4

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)

Brock Adams
  • 90,639
  • 22
  • 233
  • 295
Overloard
  • 235
  • 5
  • 16
  • Just add some CSS should be enough. Something like `GM_addStyle("a[href*='earn-google-circles'], img[src*='earn-google-circles'] { display: none !important; }");`. You even do not need GM, something like Stylish can also do this. – tsh Feb 15 '15 at 13:43
  • @tsh, That's true in this case, because it turned out to be simple (which wasn't clear when the Q was first asked). It's not that easy in cases where a simple, static, CSS selector is insufficient. – Brock Adams Feb 16 '15 at 21:00

1 Answers1

2

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:

Community
  • 1
  • 1
Brock Adams
  • 90,639
  • 22
  • 233
  • 295
  • 1
    Oh Yes! That is brilliant. Thank you Brock. Although, I did add the -435912 part because I just need 1 specific image to disappear. Without adding that bit then a bunch of other images disappeared too. Thanks again! Solved! :) – Overloard Feb 13 '15 at 08:28
  • That's great! On this site, you indicate that questions are "solved" by [ticking that little check-mark](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work/5235#5235) next to the voting buttons. – Brock Adams Feb 13 '15 at 08:45
  • 1
    Right. Sorry, I didn't know. Done! Thanks again :) – Overloard Feb 16 '15 at 13:37