For such questions, send a link to the landing page. Or, if this is not possible, save the pastebin.com page and link to it.
Anyway, the general answer to your question is not too complicated with jQuery contains () a selector . Something like this will work:
// ==UserScript== // @name _Remove annoying divs // @include http://YOUR_SERVER/YOUR_PATH/* // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js // @grant GM_addStyle // ==/UserScript== //- The @grant directive is needed to restore the proper sandbox. /*--- Use the jQuery contains selector to find content to remove. Beware that not all whitespace is as it appears. */ var badDivs = $("div div:contains('Annoying text, CASE SENSITIVE')"); badDivs.remove (); //-- Or use badDivs.hide(); to just hide the content.
Update for newly clarified question / code:
In your specific example, you would use this:
var badDivs = $("div.entry div.foo:contains('Yes')"); badDivs.parent ().remove ();
Update for the site indicated in the comments:
Please note that there is no need to search for text, because the site conveniently provides the div key to the isHot or notHot .
// ==UserScript== // @name _Unless they're hot, they're not (shown). // @include http://www.ratemyprofessors.com/SelectTeacher.jsp* // @require http://ajax.googleapis.com/ajax/libs/jquery/2.1.0/jquery.min.js // @grant GM_addStyle // ==/UserScript== //- The @grant directive is needed to restore the proper sandbox. var badDivs = $("#ratingTable div.entry").has ("div.notHot"); badDivs.remove ();
Finally, for dynamic (managed AJAX) pages
use MutationObserver or waitForKeyElements . (WaitForKeyElements also works fine on static pages.)
Here the above script is rewritten as AJAX:
Brock adams
source share