Aae34a7973a8d98e53764a1c89090c55

This one comes straight from Phillipe Lenssen's blog (http://blogoscoped.com/archive/2008-02-26-n57.html) where he shares with us this javascript bookmarklet hack to be used within friendfeed or any other web-page that uses "small" "medium" "large" parameter to encode their images...
You may need to tweak with the width and height; and with the "medium" to "large" parameters...

1
2
3
4
5
6
7
8
9
10
11
12
javascript:(function(){
    var elm = document.getElementsByTagName("img");
    for (var i = 0; i < elm.length; i++) {
        var sOld = elm[i].getAttribute("src");
        var sNew = sOld.replace(/=medium/g, "=large");
        if (sOld != sNew) {
            elm[i].setAttribute("src", sNew);
            elm[i].setAttribute("style",
                    "width:75px; height:75px");
        }
    }
})()

Refactorings

No refactoring yet !

Ed9c50a6db8b5e078b5ef84306a8477c

hubfactor

February 28, 2008, February 28, 2008 19:26, permalink

No rating. Login to rate!
1
2
3
4
5
6
7
8
9
10
11
javascript:
(function(){
  var imgs = document.getElementsByTagName("img");
  for each (var img in imgs) {
    if (img.className == "icon") continue;
    img.src = img.src.replace(/size=medium/, "size=large");
    img.style.width = "75px";
    img.style.height = "75px";
  }
}
)()
Ed9c50a6db8b5e078b5ef84306a8477c

hubfactor

March 2, 2008, March 02, 2008 16:08, permalink

No rating. Login to rate!

I hadn't realised that HTMLCollection arrays had properties other than the selected elements. I guess it's better to iterate the old way then:

1
2
3
4
5
6
7
8
9
10
11
12
javascript:
(function(){
  var imgs = document.getElementsByTagName("img");
  for (var i = 0; i < imgs.length; i++) {
    var img = imgs[i];
    if (img.className == "icon") continue;
    img.src = img.src.replace(/size=(small|medium)/, "size=large");
    img.style.width = "75px";
    img.style.height = "75px";
  }
}
)()
86d4c2dd026f9c8737ec9ddf1fbfe17c

Edd Couchman

April 8, 2008, April 08, 2008 16:47, permalink

No rating. Login to rate!

It's a good start and there isn't much to change, apart from a small optimisation of the loop and a regex for the class match (can now match if 'icon' isn't the only class).

1
2
3
4
5
6
7
8
9
10
11
12
javascript:(function () {
	var imgs = document.getElementsByTagName('img');
	for (var i = 0, j = imgs.length; i < j; i++) {
		var img = imgs[i];
		if (img.className.test("\bicon\b")) {
			continue;
		}
		img.src = img.src.replace(/size=(small|medium)/, 'size=large');
		img.style.width = '75px';
		img.style.height = '75px';
	}
})();
86d4c2dd026f9c8737ec9ddf1fbfe17c

Edd Couchman

April 8, 2008, April 08, 2008 16:49, permalink

No rating. Login to rate!

Sorry about the formatting of my last attempt...

1
2
3
4
5
6
7
8
9
10
11
12
javascript:(function () {
  var imgs = document.getElementsByTagName('img');
  for (var i = 0, j = imgs.length; i < j; i++) {
    var img = imgs[i];
    if (img.className.test("\bicon\b")) {
      continue;
    }
    img.src = img.src.replace(/size=(small|medium)/, 'size=large');
    img.style.width = '75px';
    img.style.height = '75px';
  }
})();

Your refactoring





Format Copy from initial code

or Cancel