How to block Facebook ads & junk DIVs with Opera JavaScript or GreaseMonkey script

I created the Moral Volcano Facebook page only to post on Natural News. They have moved to Disqus and don’t require Facebook anymore. Now, this wordpress blog automatically reposts everything to Twitter and Facebook. So, the ads and junk on Facebook don’t bother me. I recently created an Opera User JS and Greasemonkey script to block junk on Twitter and wondered if the same could be done for Facebook too.

animation-facebook-ad-blocker-user-js-greasemonkey-javascript

Opera User JS to block Facebook Ads and other junk

window.opera.addEventListener(
  "BeforeEvent.load", 
  function(e) {
    if (e.event.target instanceof Document) {
      try {
        disableEveryThing();
      } catch (e) {
        console.log(e);
      };
    }
  },
  false);
  

function disableEveryThing() {
  var oSE = document.createElement("style");  
  oSE.innerHTML = 
    "*[role=\"complementary\"]" +
    "{ display: none!important; } \n" +
    "*[role=\"main\"] { width: auto!important; } ";
  
  document.getElementsByTagName("head")[0].appendChild(oSE);
}

Greasemonkey Script to block Facebook Ads and Junk DIVs

// ==UserScript==
// @name        Block Junk on Facebook
// @namespace   https://www.facebook.com/
// @description %description%
// @include     https://www.facebook.com/*
// @exclude     %exclude%
// @version     1
// @grant       none
// ==/UserScript==

document.addEventListener("DOMContentLoaded", disableEveryThing(), false);

function disableEveryThing() {
  var oSE = document.createElement("style");  
  oSE.innerHTML = 
    "*[role=\"complementary\"] { display: none!important; } \n" +
    "*[role=\"main\"] { width: auto!important; } ";
  
  document.getElementsByTagName("head")[0].appendChild(oSE);
}
Advertisements