From fb24c4d8eef55ed5d925f47216c38efcaed32af3 Mon Sep 17 00:00:00 2001 From: Douglas Gardner Date: Mon, 20 May 2013 11:25:27 +0000 Subject: [PATCH] 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 --- public/imgurr.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/public/imgurr.js b/public/imgurr.js index 5c03f60..f8e5d41 100644 --- a/public/imgurr.js +++ b/public/imgurr.js @@ -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; + } }; });