Created
July 29, 2009 16:17
-
-
Save vjt/158244 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ==UserScript== | |
// @name Remove All Facebook Ads | |
// @author http://joshdick.net/programs | |
// @version 1.4 | |
// @namespace http://userscripts.org/scripts/show/13787 | |
// @description Removes any and all ads from Facebook. | |
// @include *facebook.com* | |
// ==/UserScript== | |
var sidebar_removed = false; | |
function Remove_Sidebar_Ads() { | |
if (sidebar_removed) return; | |
var sidebar_ads = document.getElementById('sidebar_ads'); | |
if (sidebar_ads && sidebar_ads.style.visibility != 'hidden') { //Prevents the visibility from being set multiple times unnecessarily | |
sidebar_ads.style.visibility = 'hidden'; | |
sidebar_removed = true; | |
} | |
} | |
Remove_Sidebar_Ads(); | |
function Remove_Dynamic_Ads() { | |
var elements = document.evaluate( | |
"//div[contains(@class, 'ad_capsule')] | //div[contains(@class, 'social_ad')] | //div[contains(@class, 'sponsor')] | //div[contains(@id, 'sponsor')]", | |
document, | |
null, | |
XPathResult.UNORDERED_NODE_SNAPSHOT_TYPE, | |
null | |
); | |
for (var i = 0; i < elements.snapshotLength; i++) { | |
var thisElement = elements.snapshotItem(i); | |
//GM_log("Removing Facebook ad element with class='" + thisElement.className + "' and id='" + thisElement.id + "'."); | |
thisElement.parentNode.removeChild(thisElement); | |
} | |
} | |
document.addEventListener("DOMNodeInserted", Remove_Dynamic_Ads, true); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment