Updated script to solve a few problems.
![]() ![]() |
I've edited your code to make it a lot more compliant with Greasemonkey conventions. (Changed element.type= to element.setAttribute() among other things.) I've also removed the recursion problem you had. Your script added the style into the head tag every time a page loads, including frames. This caused a massive memory problems as every new page that you viewed added up to 12 new blocks of code depending on how many iframes there were. Only a full page refresh (F5) would release the lines. The code now only runs on the top most window and only if the style has not been appended to the page. I have used this script in one of my own Facebook mods (ApacheFB) but it's still in Alpha testing phase atm and still heavily under construction. I've added you in the dedications. If you run with this update, it would be nice if you could do the same. :) -={Apache}=- // ==UserScript==
// @name Remove Facebook Ads (Updated By -={Apache}=-)
// @namespace sizzlemctwizzle
// @description Uses a small amount of CSS to remove advertisements.
// @require http://sizzlemctwizzle.com/updater.php?id=46560
// @version #.#.#
// @include http://*.facebook.com/*
// ==/UserScript==
window.removeFacebookAds = function() {
if (self!=top||!document.getElementsByTagName('head')[0]||document.getElementById(fb_remove_ads_style)) { return; }
var fb_remove_ads_style = document.createElement('style');
fb_remove_ads_style.setAttribute('type', 'text/css');
fb_remove_ads_style.setAttribute('id', 'fb_remove_ads_style');
try {
fb_remove_ads_style.innerHTML = '#right_column { width: 77% !important; } .ad_capsule, #sidebar_ads, .adcolumn, .emu_sponsor, div[id^="emu_"], .social_ad, .sponsor, .footer_ad, #home_sponsor, .house_sponsor, #home_sponsor_nile, .PYMK_Reqs_Sidebar, .LSplitView_RightInner { display: none !important; } #wallpage { width: 700px !important; } .LSplitView_ContentWithNoLeftColumn { width: 100% !important }';
}
catch(x) {
fb_remove_ads_style.innerText = '#right_column { width: 77% !important; } .ad_capsule, #sidebar_ads, .adcolumn, .emu_sponsor, div[id^="emu_"], .social_ad, .sponsor, .footer_ad, #home_sponsor, .house_sponsor, #home_sponsor_nile, .PYMK_Reqs_Sidebar, .LSplitView_RightInner { display: none !important; } #wallpage { width: 700px !important; } .LSplitView_ContentWithNoLeftColumn { width: 100% !important }';
}
document.getElementsByTagName('head')[0].appendChild(fb_remove_ads_style);
}
window.addEventListener("load", removeFacebookAds, false);
|
![]() ![]() |
ApacheLQ wrote:There aren't any Greasemonkey conventions. Don't just make stuff up. I've been doing this much longer than you and will call you on your bullshit. ApacheLQ wrote:You don't really understand Greasemonkey or Facebook. Greasemonkey only runs my code on a full page refresh, therefore there is only one style element added. I've even checked this myself just to make sure. Load a page in Facebook and click on a link. Then use select all and right-click View Selection Source and you will see only one style element in the head. You should have checked this yourself before accusing my script of having problems. I've been writing scripts for Facebook for over two years and already have my shit figured out. ApacheLQ wrote:This line makes me chuckle. Did you read my description page? This script doesn't use listeners or any of that memory-intensive crap. It just inserts a little CSS into the page.You don't need to wait for the page to load. Greasemonkey already executes on DOMContentLoaded, which occurs before the page loads. You also omitted the anonymous function which throws cross-browser compatibility out the window. ApacheLQ wrote:Although it's not absolutely necessary, it's probably best that it only runs on the top iframe, so I added a check for that. if (!head || self.location != top.location) {return}ApacheLQ wrote:lol like I would ever use that ugly bloated code (why not store all the style in a variable? that's what variables are for). its nearly as bad as those crappy xpath ad removers. |



