Skip to content

Instantly share code, notes, and snippets.

@RShergold
Last active August 29, 2015 14:26
Show Gist options
  • Save RShergold/e8b378bb40fcd3bcc07f to your computer and use it in GitHub Desktop.
Save RShergold/e8b378bb40fcd3bcc07f to your computer and use it in GitHub Desktop.
Imgur fusker
<style>
#images * {
width: 140px;
}
</style>
<p id='status'></p>
<div id='images'></div>
<button onclick='fusker.start()'>--go--</button>
<script>
var fusker = {
status: document.getElementById('status'),
images: document.getElementById('images'),
start: function() {
this.images.innerHTML = '';
this.tries = this.found = this.fails = 0;
for(var i=0; i<10; i++){
this.fetch();
}
},
fetch: function() {
var id = this.random_id(),
img = new Image();
img.onload = this.image_loaded.bind(this);
img.src = 'https://i.imgur.com/'+id+'s.png';
},
random_id: function() {
var id = '';
do {
id += 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'[~~(Math.random() * 62)];
} while (id.length < 5);
return id;
},
image_loaded: function(e) {
var image = e.target;
this.tries++;
if (image.width==161 && image.height==81){
this.fails++;
} else {
var dom_element = document.createElement('a');
dom_element.href = "http://imgur.com/"+image.src.match(/(\w+)s.png/)[1];
dom_element.target = '_blank';
dom_element.appendChild(image);
this.images.appendChild(dom_element);
this.found++;
}
this.status.innerText = 'tries:'+this.tries+' found: '+this.found+' fails:'+this.fails;
if (this.found<1000) this.fetch();
}
};
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment