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 !
hubfactor
February 28, 2008, February 28, 2008 19:26, permalink
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";
}
}
)()
hubfactor
March 2, 2008, March 02, 2008 16:08, permalink
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:
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";
}
}
)()
Edd Couchman
April 8, 2008, April 08, 2008 16:47, permalink
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).
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';
}
})();
Edd Couchman
April 8, 2008, April 08, 2008 16:49, permalink
Sorry about the formatting of my last attempt...
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';
}
})();
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...