2013-04-15 03:10:29 +02:00
|
|
|
!!! 5
|
|
|
|
html(lang='en')
|
|
|
|
head
|
|
|
|
meta(charset='utf-8')
|
|
|
|
script(type="text/javascript", src="//ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js")
|
2013-04-15 03:50:50 +02:00
|
|
|
link(rel="stylesheet", href="/imgurr.css")
|
2013-04-15 03:10:29 +02:00
|
|
|
title random imgur
|
|
|
|
script
|
2013-04-15 23:55:50 +02:00
|
|
|
var count = 0;
|
2013-04-17 22:55:34 +02:00
|
|
|
function giveMessage(msg) {
|
|
|
|
$('<li>'+msg+'</li>').prependTo('#history').hide().slideDown();
|
|
|
|
}
|
2013-04-17 23:30:05 +02:00
|
|
|
var lock = false
|
2013-04-19 02:02:39 +02:00
|
|
|
var highscore = #{highscore} + 1;
|
|
|
|
var score = highscore;
|
|
|
|
$('#count').text(score);
|
2013-04-16 18:42:57 +02:00
|
|
|
function getNewImage() {
|
2013-04-15 23:55:50 +02:00
|
|
|
count += 1;
|
2013-04-17 23:30:05 +02:00
|
|
|
lock = true;
|
2013-04-17 22:02:36 +02:00
|
|
|
$('#loading').fadeIn();
|
2013-04-16 18:42:57 +02:00
|
|
|
$('#loading').text('Loading image ' + count + '...');
|
2013-04-16 23:03:50 +02:00
|
|
|
document.title = 'random imgur (' + count + ')';
|
|
|
|
$('#loading').fadeIn();
|
2013-04-16 18:42:57 +02:00
|
|
|
$('#image').load(function(){});
|
|
|
|
$.get("/api/imgur/getRandomImage", function(d) {
|
|
|
|
$('#image').attr('src', d.data[0]);
|
2013-04-17 23:30:05 +02:00
|
|
|
lock = false;
|
2013-04-19 02:02:39 +02:00
|
|
|
score -= 1;
|
|
|
|
$('#count').text(score);
|
2013-04-16 23:03:50 +02:00
|
|
|
$('#details').text("Fetching info...");
|
2013-04-17 22:55:34 +02:00
|
|
|
giveMessage('<a href="' + d.data[0] + '">' + d.data[0] + '</a>');
|
2013-04-16 18:42:57 +02:00
|
|
|
$.get("/api/imgur/getImageInfoString", { 'slug': d.data[1] }, function(info) {
|
2013-04-17 22:02:36 +02:00
|
|
|
if(info.data[0].indexOf('undefined') == -1) {
|
|
|
|
$("#details").text(count + ': ' + info.data[0]);
|
|
|
|
$('#details').show();
|
|
|
|
} else {
|
|
|
|
$("#details").hide();
|
|
|
|
}
|
|
|
|
$('#loading').fadeOut();
|
2013-04-16 18:42:57 +02:00
|
|
|
}, "json");
|
|
|
|
}, "json");
|
|
|
|
}
|
|
|
|
$(getNewImage());
|
2013-04-17 22:55:34 +02:00
|
|
|
$(document).on('keydown', function(e){
|
|
|
|
switch(e.which){
|
2013-04-19 02:02:39 +02:00
|
|
|
case 82: // r
|
|
|
|
score = highscore;
|
|
|
|
$('#count').text(highscore);
|
|
|
|
giveMessage("Score reset.");
|
2013-04-17 22:55:34 +02:00
|
|
|
case 13: // enter
|
|
|
|
case 32: // space
|
2013-04-17 23:30:05 +02:00
|
|
|
if (lock) {
|
|
|
|
$('#loading').text(function(index, text){
|
|
|
|
return text.replace(/\.(?=[^.]*$)/, "!");
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
getNewImage();
|
|
|
|
}
|
2013-04-17 22:55:34 +02:00
|
|
|
break;
|
2013-04-19 02:02:39 +02:00
|
|
|
case 67:
|
|
|
|
$('#count').fadeToggle();
|
|
|
|
break;
|
2013-04-17 22:55:34 +02:00
|
|
|
case 83: // s
|
|
|
|
$('body').toggleClass('crop');
|
|
|
|
giveMessage("Toggled scrollbars.")
|
|
|
|
};
|
|
|
|
});
|
2013-04-15 03:10:29 +02:00
|
|
|
body
|
2013-04-16 23:03:50 +02:00
|
|
|
div#loading Loading image 1...
|
2013-04-16 19:47:01 +02:00
|
|
|
div#details Press [SPACE] to load a new image
|
2013-04-19 02:02:39 +02:00
|
|
|
div#count
|
|
|
|
#{highscore}
|
2013-04-17 22:55:34 +02:00
|
|
|
ul#history
|
|
|
|
li Press [SPACE] for next
|
2013-04-15 03:10:29 +02:00
|
|
|
div#container
|
2013-04-15 03:50:50 +02:00
|
|
|
img#image
|