3 ms·
This was a fun little project that started from a co-worker wanting to see random imgur files. I've just started playing with jQuery and JavaScript and this is
by symkat 15y ago
This was a fun little project that started from a co-worker wanting to see random imgur files. I've just started playing with jQuery and JavaScript and this is the result so far.
Imgur uses 5 chars alphanumerical ids as the image names, and doesn't care if you use .jpg, .png, etc, etc. So I wrote a small backend that generates and spits out an array of keys to check. The JavaScript hides the image tag, and sets it, another function verifies that it's a real image (imgur sends 200s, and an image that tells you an image doesn't exist, so I check that the height and width match). If it does, then display the image, if not, try the next. When the array is about to run out, I fill it again. I also keep a small cache of the keys that it determined weren't valid (based on jQuery passing back to me the list of failed keys) to try to up the odds of getting an image quicker.
An unmini'ed version of the JavaScript is at http://image-roulette.com/static/js/image-roulette.js http://image-roulette.com/static/js/image-roulette.js
Any feedback would be awesome =)