How to hide certain elements using Greasemonkey?

别等时光非礼了梦想. 提交于 2019-12-17 19:56:13

问题


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)


回答1:


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:

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


来源:https://stackoverflow.com/questions/28494111/how-to-hide-certain-elements-using-greasemonkey

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!