Search code examples
userscripts

removing an element with a userscript


First attempt at a userscript, and despite finding numerous examples on the internet of how to remove elements from a page, none of them work (and this looks like one of the most basic applications of a userscript, too).

Using violentmonkey-2.12.8 on this page:

https://www.zerohedge.com/economics/2020-greatest-hits-most-popular-articles-past-year-and-look-ahead

I want to remove the "exitModalOverlay" div (disabling it in the developer tools does exactly what I want), which blacks out the page (preventing me from reading it).

I will insert one of the more common techniques I have found (which doesn't work). I would appreciate any method which does. Thanks.

// ==UserScript==
// @namespace   confused
// @name        zehohedge_remove_subscription_popup
// @version     1
// @description removes the overlay div that asks to subscribe
// @match       https://www.zerohedge.com/*
// @grant       none
// @noframes
// ==/UserScript==

var todelete = document.getElementById('exitModalOverlay');
if (todelete) { todelete.parentNode.removeChild(todelete); }


Solution

  • Maybe so...

    window.onload = function() {
    var todelete = document.querySelector('#exitModalOverlay');
    todelete.outerHTML = '';
    }
    

    or

    window.onload = function() {
    var todelete = document.querySelector('#exitModalOverlay');
    todelete.remove();
    }