views:

544

answers:

6

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 :)

A: 

Do you know that the images still load? Maybe you should assert it using Firebug or some such?

PEZ
+4  A: 

If you want to disable images downloading for all websites (which I guess you might not be doing) and are using firefox, why not just disable them in preferences? Go to the content tab and switch off "Load images automatically".

GaryF
+1  A: 

I believe greasemonkey script are executed after the loading of the page, so I guess the images are loaded too.

Ikke
Greasemonkey scripts are actually initiated on the DOMContentLoaded event meaning that images will not necessarily be loaded. Source: http://wiki.greasespot.net/DOMContentLoaded
J-P
In the face of ambiguity, refuse the temptation to guess.(c) Zen of Python -- most of images are not loaded (at least in my setup and from the link posted by @JimmyP follows it is a common case).
J.F. Sebastian
+1  A: 

I know it's not greasemonkey, but you could try the "IMG Like Opera" extenstion. It definitely keeps the files from downloading, and has more flexibility than just on/off.

sep332
+1  A: 

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.

J.F. Sebastian
+1  A: 

Not entirely related, but I use this bit of code to toggle displaying of images in Firefox in the EasyGestures plugin. I am not sure if this can be translated to greasemonkey, but it might be a starting point.

var prefs = Components.classes["@mozilla.org/preferences-service;1"].
            getService(Components.interfaces.nsIPrefBranch);
var nImgPref = prefs.getIntPref("permissions.default.image");
if (nImgPref == 1) {
  prefs.setIntPref("permissions.default.image",2)
  alert('Images off.');
} else {
  prefs.setIntPref("permissions.default.image",1)
  alert('Images on.');
}
Zoredache