diff --git a/modules/imgur/imgur.js b/modules/imgur/imgur.js index e84a4a9..11ea1c3 100644 --- a/modules/imgur/imgur.js +++ b/modules/imgur/imgur.js @@ -9,12 +9,11 @@ var _ = require('underscore')._, var imgur = function(dbot) { this.internalAPI = { 'infoString': function(imgData) { - info = null; + info = ''; if(imgData && _.has(imgData, 'data')) { imgData = imgData.data; - info = '['; if(imgData.title) { - info += imgData.title + ']['; + info += imgData.title + ' - '; } if(imgData.type) { if(imgData.animated) { @@ -26,7 +25,7 @@ var imgur = function(dbot) { info += 'an image with '; } info += imgData.views + ' views ('; - info += imgData.width + 'x' + imgData.height + ')].'; + info += imgData.width + 'x' + imgData.height + ')'; } return info; @@ -55,6 +54,12 @@ var imgur = function(dbot) { }.bind(this)); }, + 'getImageInfoString': function(slug, callback) { + this.api.getImageInfo(slug, function(imgData) { + callback(this.internalAPI.infoString(imgData)); + }.bind(this)); + }, + 'getImageInfo': function(slug, callback) { request.get({ 'url': 'https://api.imgur.com/3/image/' + slug + '.json', @@ -69,13 +74,15 @@ var imgur = function(dbot) { }; this.api['getRandomImage'].external = true; this.api['getRandomImage'].extMap = [ 'callback' ]; + this.api['getImageInfoString'].external = true; + this.api['getImageInfoString'].extMap = [ 'slug', 'callback' ]; this.commands = { '~ri': function(event) { this.api.getRandomImage(function(link, slug) { this.api.getImageInfo(slug, function(imgData) { var info = this.internalAPI.infoString(imgData); - event.reply(event.user + ': ' + link + ' ' + info); + event.reply(event.user + ': ' + link + ' [' + info + ']'); }.bind(this)); }.bind(this)); } @@ -86,7 +93,7 @@ var imgur = function(dbot) { if(matches[1]) { this.api.getImageInfo(matches[1], function(imgData) { var info = this.internalAPI.infoString(imgData); - if(info) event.reply(info); + if(info) event.reply('[' + info + ']'); }.bind(this)); } }.bind(this); diff --git a/public/imgurr.css b/public/imgurr.css index 58b668d..f2a0cff 100644 --- a/public/imgurr.css +++ b/public/imgurr.css @@ -13,7 +13,6 @@ border-bottom-right-radius:5px; border-top-right-radius:5px; color:#85bf25; - display:none; font-family:sans-serif; font-weight:700; left:0; diff --git a/views/imgur/imgurr.jade b/views/imgur/imgurr.jade index 517e9fe..1a1440b 100644 --- a/views/imgur/imgurr.jade +++ b/views/imgur/imgurr.jade @@ -7,15 +7,19 @@ html(lang='en') title random imgur script var count = 0; - function wat() { + function getNewImage() { count += 1; - $('#loading').text('Loading image ' + count); - $('#loading').show(); - $('#image').load(function(){$('#loading').hide(); console.log('loaded')}); - $.get("/api/imgur/getRandomImage", function(d) {$('#image').attr('src', d.data[0])}, "json"); - }; - $(wat()); - $(document).on('keydown', function(e){(e.which==32)&&(wat()) }); + $('#loading').text('Loading image ' + count + '...'); + $('#image').load(function(){}); + $.get("/api/imgur/getRandomImage", function(d) { + $('#image').attr('src', d.data[0]); + $.get("/api/imgur/getImageInfoString", { 'slug': d.data[1] }, function(info) { + $("#loading").text(count + ': ' + info.data[0]); + }, "json"); + }, "json"); + } + $(getNewImage()); + $(document).on('keydown', function(e){(e.which==32)&&(getNewImage()) }); body div#loading Loading Image div#container