Improvements
|
|
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. |
|
|
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, |
|
|
>on the setInterval, i used an anonymous function because those are preferred
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 :)
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
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
|
|
|
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 |
|
|
I'll see, thanks |
|
|
got another new one: #home_sponsor |
|
|
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 ;) |