Search code examples
javascriptgreasemonkey

Removing images with Greasemonkey?


I would like to stop images from loading, as in not even get a chance to download, using greasemonkey. Right now I have

var images = document.getElementsByTagName('img');

for (var i=0; i<images.length; i++){
    images[i].src = "";
}

but I don't think this actually stops the images from downloading. Anyone know how to stop the images from loading?

Thanks for your time and help :)


Solution

  • Almost all images are not downloaded. So your script almost working as is.

    I've tested the following script:

    // ==UserScript==
    // @name           stop downloading images
    // @namespace      http://stackoverflow.com/questions/387388
    // @include        http://flickr.com/*
    // ==/UserScript==
    
    var images = document.getElementsByTagName('img');
    for (var n = images.length; n--> 0;) {
      var img = images[n];
      img.setAttribute("src", "");
    }
    

    Use a dedicated extension to manage images (something like ImgLikeOpera).

    If you'd like to filter images on all browser then a proxy with filtering capabilities might help e.g., Privoxy.