Register a SA Forums Account here!
JOINING THE SA FORUMS WILL REMOVE THIS BIG AD, THE ANNOYING UNDERLINED ADS, AND STUPID INTERSTITIAL ADS!!!

You can: log in, read the tech support FAQ, or request your lost password. This dumb message (and those ads) will appear on every screen until you register! Get rid of this crap by registering your own SA Forums Account and joining roughly 150,000 Goons, for the one-time price of $9.95! We charge money because it costs us money per month for bills, and since we don't believe in showing ads to our users, we try to make the money back through forum registrations.
 
  • Post
  • Reply
argz
May 20, 2005

The hand says it all.
I'm trying to write a greasemonkey script to replace the tiny rear end thumbnails on gnome-look.org (seriously 80px by 50px? This is 1990, jesus christ). Only problem, is there is no consistency in the thumbnail to fullsize image extensions. A png thumb can be a jpg fullsize, a png fullsize or quite possibly a gif and any other combination like this.

The solution here is to do an image check. Unfortunately, I'm a javascript idiot and I've gotten stuck on this problem while trying to solve it different ways. The one I _thought_ would be successful was most certainly not, that was using a global var to set and test true/false.

Can someone please help me out and liberate me from this ancient website?

code:
// ==UserScript==
// @name           gnome-look.org big pic
// @namespace      buttface
// @version        1.0.0
// @description    Replace large images in posts to thumbnailed version
// @include        [url]http://gnome-look.org*[/url]
// @include        [url]http://*.gnome-look.org*[/url]
// ==/UserScript==

// Well this global didn't work
// var exists=false;

function $xu(p, c) {
	var i, r = [], x = document.evaluate(p, c || document, null, XPathResult.UNORDERED_NODE_ITERATOR_TYPE, null);
	while(i=x.iterateNext()) r.push(i);
	return r;
}
$xu('//IMG[contains(@src, "content-m1")]').forEach(function(img) {

		var src = img.src.replace(/\/content-m1\/m/i, '/content-pre1/');

		//testImage(src);
		//if (exists==false) {
		if (testImage(src)==false) {
			alert(src);
			src = src.replace(/.png/i, '.jpg');
		}
		
		if (testImage(src)==false) {
			alert(src);
			src = src.replace(/.jpg/i, '.gif');
		}
		
		if (testImage(src)==false) {
			alert(src);
			src = src.replace(/.gif/i, '.png');
		}
		
		img.src = src;
		
		img.removeAttribute('width');
		img.removeAttribute('height');

});


function testImage(URL) {
    var tester=new Image();

	tester.onError=isBad;
	tester.onLoad=isGood;
	
	return exists;
    /*if (tester.onError) {
		return false;
	} else {
		return true;
	}*/
}

function isGood() {
	//exists = true;
	return false;
}

function isBad() {
    //alert('That image does no exist!');
	//exists = false;
	return false;
}

Adbot
ADBOT LOVES YOU

argz
May 20, 2005

The hand says it all.
Well the actual check whether the image exists or not works, no XHR necessary there. The problem I'm having is looping it.

argz
May 20, 2005

The hand says it all.
Well, this looks like the better solution. I appreciate the rewrite and I will learn from it. It works great in Opera, however, my main browser, Firefox doesn't seem to make it to the following function in the second parameter at line 18:

code:
fixImageExtension(fullSizePath + thumbnailName, function(fixedUrl) {
        alert("yo, I'm firefox, a big jerk that doesn't like to visit this place");
	if (fixedUrl) img.src = fixedUrl;
});

argz
May 20, 2005

The hand says it all.
Still not working for me, receiving the following error in console:

Firefox 3.0.8 on Linux

code:
Error: Component is not available
Source File: file:///home/argz/.mozilla/firefox/wdkx9mw3.default/gm_scripts/gnome-lookorg_thumbnail_/gnome-lookorg_thumbnail_.user.js
Line: 41
:doh:

argz
May 20, 2005

The hand says it all.
Thanks NigglyPuff, you're my hero! I'm going to browse me some themes :snoop:


By the way, https://www.kde-look.org runs on the same outdated software if you'd like to get double points on userscripts.org or add them to the top of this one like I did.


Thanks again :D

argz
May 20, 2005

The hand says it all.

Other Door posted:

I need them not to repeat. Once image 3 has been displayed I want it to move on to the next random image and never show image 3 again. Is this possible?

pop it off the array.

Adbot
ADBOT LOVES YOU

argz
May 20, 2005

The hand says it all.

Other Door posted:

how? I've tried the splice command with no success.

randomize the order of your array, then use pop

http://www.w3schools.com/jsref/jsref_pop.asp

  • 1
  • 2
  • 3
  • 4
  • 5
  • Post
  • Reply