removing block of html(no element ID)

Subscribe to removing block of html(no element ID) 7 posts, 4 voices

 
schwim User

Hi there everyone,

I downloaded the two greasemonkey scripts that were supposed to removed the sponsor block from the sitepoint forums, but neither worked.

I've noticed that there are no unique element ID's to help me in my task. tcat and alt2 are shared by other parts of of the page.

Here's the code:

EDIT: I've removed the code due to the inability to keep it from parsing. I want to remove a table with class "tborder product".

I would like to make this code disappear.

Could someone help me with this task?

Thanks very much for your time.
json

 
Mindeye Scriptwright

You want to remove a table with class "tborder product". An Xpath expression like "//table[@class='tborder product']" would be enough


var ad = $x("//table[@class='tborder product']")[0];
if (ad) ad.parentNode.removeChild(ad);

You can get the $x function in the GreaseSpot wiki (http://wiki.greasespot.net/Code_snippets#XPath_...)

 
Descriptor Scriptwright

I believe that will throw an error if the array is empty.

OK, because that function defines arr = [] an empty Array, so your code only produces a warning, but not a fatal error. Still better to check (ad) or it's length before trying to access an item. Would be easier to modify that function to use FIRST_ORDERED_NODE_TYPE, unless the first isn't the one you want.

 
schwim User

Hi there mindeye, and thanks very much for the response.

If I can manage to do it, this would be my first greasemonkey script and although I'm reading everything I can find, I'm having a problem actually assembling the code.

I see that the wiki explains the different things I can do once I've identified the code, but to be honest, I can't determine which I'm supposed to use, as the docs don't seem to be intended to be used by a layman.

Would you mind helping me a bit more with what I need to do to bring the script to fruition?

thanks very much for the time you've already spent on it.

thanks,
json

 
schwim User

Sorry descriptor, I missed your post when replying.

Are you saying that mindeye's snippet is the code in an of itself, but it needs some modification?

thanks,
json

 
Descriptor Scriptwright It's perfectly fine, but if it was written like this...
var ad = $x("//table[@class='tborder product']");
if (ad.length) ad[0].parentNode.removeChild(ad[0]);

There wouldn't be any (strict) JavaScript warning... when the ad doesn't exist.

-- All you need is that XPath helper function from the link Mindeye supplied, and his two lines of code.

 
Mikado Scriptwright

GM_addStyle('.tborder.product,.industrybrains{display:none}');

Also, Stylish.