Remove tag based on sub tag data?

Posting here is no longer possible, please use the forum of a filter list project, such as EasyList
Locked
JEmlay
Posts: 6
Joined: Thu Dec 27, 2012 6:05 pm

Remove tag based on sub tag data?

Post by JEmlay »

Is there anyway to remove a tag based on data found from a sub tag?

Example:

Code: Select all

<li class="NS_comments__comment comment item mb2 more py2" id="comment-9667143">
<div class="comment-inner">
<div class="avatar left">
<a href="/profile/999999999999"><img alt="" class="circle" height="80" width="80" /></a>
</div>
<div class="main clearfix pl2 ml2">
<h3>
<span class="creator">Creator</span>
<a class="author green-dark" href="/profile/9999999999999">NAME</a>
</h3>
<p>blah blah blah</p>
<span class="loading icon-loading-small" style="display:none;"></span>
</div>
</div>
</li>
I've come across this many times. It would extremely helpful to be able to remove that entire LI based on the A tags HREF that equals = /profile/999999999999. On many boards and blogs this would help to remove comments from specified people who you never want to hear from again.

Something along the lines of li.div.div.a[href="/profile/9999999999999"]

Thanks for any help!
User avatar
mapx
Posts: 21940
Joined: Thu Jan 06, 2011 2:01 pm

Re: Remove tag based on sub tag data?

Post by mapx »

no, ABP can't do this (probably not before the arrival of css4 selectors). You need a userscript (in greasemonkey / tampermonkey).

Could you provide an example page for your question ?
JEmlay
Posts: 6
Joined: Thu Dec 27, 2012 6:05 pm

Re: Remove tag based on sub tag data?

Post by JEmlay »

mapx wrote:no, ABP can't do this (probably not before the arrival of css4 selectors). You need a userscript (in greasemonkey / tampermonkey).

Could you provide an example page for your question ?
Thanks for the reply. I figured as much. Doesn't hurt to ask though!

For my example above I used the Kickstarter comments section of a project.

Say a page like this:

https://www.kickstarter.com/projects/18 ... r/comments

You'll find the above LI tag structure on that page.
lewisje
Posts: 2743
Joined: Mon Jun 14, 2010 12:07 pm

Re: Remove tag based on sub tag data?

Post by lewisje »

They key to getting parent tags is XPath, and the key to XPath is document.evaluate (available in all reasonably recent browsers except IE): https://developer.mozilla.org/en-US/doc ... t/evaluate

If you ever do want to use XPath in IE, here's a polyfill for IE5+: http://sourceforge.net/projects/js-xpath/

Either that or you could just use Sizzle, which is part of jQuery, and then feed in the ":has()" selector that once was a jQuery extension and now is on track to become part of CSS4.
There's a buzzin' in my brain I really can't explain; I think about it before they make me go to bed.
User avatar
mapx
Posts: 21940
Joined: Thu Jan 06, 2011 2:01 pm

Re: Remove tag based on sub tag data?

Post by mapx »

script (installed in greasemonkey / tampermonkey) which removes the comments for a user:

example page: https://www.kickstarter.com/projects/53 ... y/comments

I want to hide the comments of Shawna Kaszer and Brian (for other users replace Shawna or Brian in the main function with the user you want to block) using the name itself

Code: Select all

// ==UserScript==
// @name     hide comments
// @include  *.kickstarter.com/*
// @require  https://code.jquery.com/jquery-2.1.3.min.js
// ==/UserScript==

function addJQuery(callback) {
  var script = document.createElement("script");
  script.setAttribute("src", "https://code.jquery.com/jquery-2.1.3.min.js");
  script.addEventListener('load', function() {
    var script = document.createElement("script");
    script.textContent = "(" + callback.toString() + ")();";
    document.body.appendChild(script);
  }, false);
  document.body.appendChild(script);
}

// load jQuery and execute the main function
addJQuery(main);

function main() {
$("li.NS_comments__comment").has ("a:contains('Shawna Kaszer')").hide ();
$("li.NS_comments__comment").has ("a:contains('Brian')").hide ();

}

        
to hide using the profile info (/profile/53195090) replace the main function by this 1:

Code: Select all

function main() {
$("li.NS_comments__comment").has ('a[href="/profile/53195090"]').hide ();
}
JEmlay
Posts: 6
Joined: Thu Dec 27, 2012 6:05 pm

Re: Remove tag based on sub tag data?

Post by JEmlay »

Oh wow, I wasn't expecting anyone to flat out write the whole thing.

THANK YOU!

That is spot on perfect. Not to mention an excellent example to fork off onto other sites. Profile number would be much better as that can't be changed. Anyone can change their name.

Thank you mapx, more than words can even say for taking the time to do that for me.

I greatly appreciate it!
Locked