De-ad Facebook

By diego.devita Last update Nov 26, 2008 — Installed 11,606 times.

Improvements

in
Subscribe to Improvements 7 posts, 2 voices



diego.devita Script's Author

yes, I know what XPath is...I thought it was heavier to execute compared to dom. But much easier to mantain and develop, especially if the expression is really complex. why? because it's much more powerful and needs to run a big parser. I thought that simply looking for div and iframe elements was not complex enough to disturb the xpath parser and I preferred the getElementByTagName to make it lighter.

Anyway I'm not sure, I should profile the javascript performance and compare the two options and then make a final decision. Probably you're right.

About your code, you generalized the activity. So instead of having two different functions there's one. It's a good idea...I've always postponed that job because the script was changing too often. But now it's time to take this path. I'm going to update the script in the next hours.

I chose to run the script every half a second because I noticed I couldn't be sure of the result if it ran only once as an onload handler. Actually this is a choice I adopted since another script of mine on GMail. So I decided to keep this solution on any other script I did...just to be sure. Do you think there's no need on facebook? will it work in any circumstance and page on facebook just if it runs once on the beginning? I don't think it hurst in some way, don't you think is safer to leave an harmless feature?

thanks for the help.

 
Avindra V.G. Scriptwright

with the latest version, how about this:

//removes elements got by [tagName] where [attribute] match the [regex]
function remove(tagName, attribute, regex) {	
	var nodes = document.getElementsByTagName(tagName);	
	for (i in nodes){		
		obj = nodes[i];
		value = obj.getAttribute(attribute);
		if (regex.test(value)) obj.parentNode.removeChild(obj);
	} 
}

//hide sidebar ads, removes on the home section: the sidebar sponsor area and the sponsored feeds
GM_addStyle('#sidebar_ads, .social_ad, .sponsor { display:none !important }');

//tries to remove unknown ads using generic patterns
//actually every box on every page that could contain a banner
//every half second

setInterval(function(){
	remove('iframe','src',/([^\w][aA]d[^d]|\/\w{1,3}\.(php|htm|html)\?|monetize|banner)/);
},500);

on the setInterval, i used an anonymous function because those are preferred, and I removed the "main" function so that it just executes through.

Also for adding CSS styles, GM_addStyle exists in the greasemonkey api. Also, I combined your css styles, and changed the selectors to simpler versions.

 
diego.devita Script's Author

>on the setInterval, i used an anonymous function because those are preferred
>and I removed the "main" function so that it just executes through.

I see, I did that way because I don't like confusion. I prefer giving the code a meaning. It comes easier to comment and understand. So generally I try to keep low the coupling till I can. But as a matter of fact the code (now) is quite small, I'm going to make the remove function more specific too. So there's no more need of additional functions they make noise now.

> Also for adding CSS styles, GM_addStyle exists in the greasemonkey api.

I didn't know yet so I copied the function from diveintogreasemonkey. If I can use that one I'll do that way.

> Also, I combined your css styles, and changed the selectors to simpler versions.

this is your css style: '#sidebar_ads, .social_ad, .sponsor { display:none !important }'

you changed the way I get access to an element and applied the same style to all the selectors.

about the first I say yes you're right. I was so focused on XPath that I completely ignored the first css rule :)
I have to say that it's a bit more generic because it gets also non div elements. anyway I'm going to do that way because it's a class much focused on advertisments.

about the second, I see, but there's a reason if I chose different styles. this is a citation:

Well, display: none entirely removes the element from the page, and
the flow of the page is calculated as though the element were not
there at all. On the other hand, visibility: hidden leaves the
space in the document flow even though you can no longer see the
element. Depending on what you are doing, that can make a huge
difference or be no big deal.

So when I choose visibility:hidden rather than display:none it's because I don't want to screw up the layout. This happens for example with the sidebar in the profile page. Here's why I use 2 different styles and can't use your simplification in this case.

brief summary:

-more specific remove function, because I only need to catch the iframe.src since I use css
-the remove function is so specific that there's no need of another wrapper, the setInterval calls an anonymous function now (in a quite clean way)
-css selectors are .classname instead of div[@class=classname]
-use of GM_addStyle instead of my custom function
-no more main function because the code is so clear now that I don't need more grouping nor use it as an event handler

 
Avindra V.G. Scriptwright

Looking good ;)

also, I'm not sure if these are applicable any more, but they used to block some ads:

.UICompatibilityFrame_FooterAdsContainer, [class$="SidebarAds"], .profile_sidebar_ads, .ad_capsule, .adcolumn 

 
diego.devita Script's Author

I'll see, thanks

 
Avindra V.G. Scriptwright

got another new one:

#home_sponsor

 
diego.devita Script's Author

thanks avg for your suggestion...I have been busy lately, but in the next days I'm going to renew the script. I didn't stop using it and I can see it doesn't work well as before. hope someone will appreciate the effort, even if I guess meanwhile something else grew up ;)

Cross
Presentational HTML allowed.
Use <code> for inline code and <pre> for code blocks. Use &lt; and &gt; for literal < and >.
We help break paragraphs and link your links.
or cancel