Add 5s timer functionality to random imgur

* Add [.] key to enable timer
* "Loading..." message turns red and italic when timer is active
* Press [.] key to disable timer.

After a bit of experimentation, 5s seemed optimal: 2 seconds would cause
the imgur api to trip if the app is used more than once at a time; 5
seconds is enough time to view the image without feeling particularly
slow.

Maximums:
 1 images in 5 seconds
3600 images in 5 minutes
43200 images in an hour
This commit is contained in:
Douglas Gardner 2013-05-20 11:25:27 +00:00
parent 5fd2a3923f
commit fb24c4d8ee

View File

@ -49,6 +49,7 @@ function getNewImage() {
$(getNewImage());
var t;
$(document).on('keydown', function(e){
switch(e.which){
case 82: // r
@ -72,5 +73,21 @@ $(document).on('keydown', function(e){
case 83: // s
$('body').toggleClass('crop');
giveMessage("Toggled scrollbars.")
break;
case 190: // .
if(!t){
giveMessage("Automation on.");
$('#loading').css("font-style", "italic");
$('#loading').css("color","#BF2527");
t = setInterval(function(){
getNewImage();
},5000);
} else {
giveMessage("Automation off.");
$('#loading').css("font-style","normal");
$('#loading').css("color","#85BF25");
clearTimeout(t);
t = undefined;
}
};
});