Search code examples
javascriptcssgoogle-chrome-extensiongoogle-chrome-devtoolsadblock

How to remove the css rule "body overflow:hidden" automatically


In some web pages entering with adblock installed is added in the body the "overflow:hidden" css style, preventing the scroll of a website.

Example:

<html>
  <head>
      <title>Website</title>
  </head>
  <body style="overflow: hidden;">
    Some long article content
  </body>
</html>

I have to manually edit in Chrome web inspector to remove each time, which is annoying.

I would like know I could make this removal permanent or detect via a chrome extension or adblock rule to remove it or maybe via a direct javascript, etc.

UPDATE: Using tampermonkey chrome extension, probably I could reach my goal. I did the following script without result (the page seems reload or load some javascript and I cannot remove properly the body overflow hidden):

// ==UserScript==
// @name         InvestingRemoveScrollBodyBlocker
// @namespace    http://tampermonkey.net/
// @version      0.1
// @description  Remove body overflow hidden
// @author       Ángel Guzmán Maeso <angel@guzmanmaeso.com>
// @match        https://*.investing.com/*
// @grant        none
// ==/UserScript==

(function() {
    'use strict';

    setTimeout(function(){

        var bodyWeb = document.getElementsByTagName("BODY")[0];
        console.log(bodyWeb);
        bodyWeb.style.overflow = "visible !important";

    }, 4000);

})();

Solution

  • Try this script tool TamperMonkey

    To override overflow

    body {
       overflow: visible !important;
    }
    

    The script that will work with TamperMonkey:

    // ==UserScript==
    // @name         InvestingRemoveScrollBodyBlocker
    // @namespace    http://tampermonkey.net/
    // @version      0.2
    // @description  Remove body overflow hidden
    // @author       Ángel Guzmán Maeso <angel@guzmanmaeso.com>
    // @match        https://*.investing.com/*
    // @grant        none
    // ==/UserScript==
    
    (function() {
        'use strict';
        // Credits: https://stackoverflow.com/questions/51330252/how-to-remove-the-css-rule-body-overflowhidden-automatically
        document.body.style.cssText = "visible !important";
    })();